際際滷

際際滷Share a Scribd company logo
Applying Object Composition
to Build Rich Domain Models
Zoran Horvat
CEO & Principal Consultant, Coding Helmet Consultancy
zh@sysexpand.com
http://codinghelmet.com
zoranh75
https://pluralsight.com/authors/zoran-horvat
zh@sysexpand.com
http://codinghelmet.com
zoranh75
Watch the webinar recording here:
https://www.postsharp.net/blog/we
binar-recording-object-composition
Applying Object Composition to Build Rich Domain Models
Applying Object Composition to Build Rich Domain Models
Applying Object Composition to Build Rich Domain Models
Applying Object Composition to Build Rich Domain Models
Applying Object Composition to Build Rich Domain Models
Applying Object Composition to Build Rich Domain Models
Applying Object Composition to Build Rich Domain Models
Applying Object Composition to Build Rich Domain Models
Applying Object Composition to Build Rich Domain Models
Applying Object Composition to Build Rich Domain Models
Animal obj = ...
Animal obj = ...
if (obj is Mammal)
{
}
Animal obj = ...
if (obj is Mammal)
{
Mammal mammal = (Mammal)obj; // e.g. a tiger
}
Animal obj = ...
if (obj is Mammal)
{
Mammal mammal = (Mammal)obj; // e.g. a tiger
// Pull mammals tail using all your strength
}
Animal obj = ...
if (obj is Mammal)
{
Mammal mammal = (Mammal)obj; // e.g. a tiger
// Pull mammals tail using all your strength
// Run as fast as you can
}
Animal obj = ...
if (obj is Mammal)
{
Mammal mammal = (Mammal)obj; // e.g. a tiger
// Pull mammals tail using all your strength
// Run as fast as you can
}
Applying Object Composition to Build Rich Domain Models
Applying Object Composition to Build Rich Domain Models
Animal obj = ...
if (obj is Mammal)
{
Mammal mammal = (Mammal)obj; // e.g. a tiger
// Pull mammals tail using all your strength
// Run as fast as you can
}
Animal obj = ...
if (obj is Mammal)
{
Mammal mammal = (Mammal)obj; // e.g. a tiger
// Pull mammals tail using all your strength
// Run as fast as you can
}
else if (obj is WaterMammal)
{
WaterMammal mammal = (WaterMammal)obj; // e.g. a whale
// Pull mammals fins using all your strength
// Swim as fast as you can
}
Animal obj = ...
if (obj is Mammal)
{
Mammal mammal = (Mammal)obj; // e.g. a tiger
// Pull mammals tail using all your strength
// Run as fast as you can
}
else if (obj is WaterMammal)
{
WaterMammal mammal = (WaterMammal)obj; // e.g. a whale
// Pull mammals fins using all your strength
// Swim as fast as you can
}
Logic
duplication,
but no true
code duplication!
Animal obj = ...
if (obj is Mammal)
{
Mammal mammal = (Mammal)obj; // e.g. a tiger
// Pull mammals tail using all your strength
// Run as fast as you can
}
else if (obj is WaterMammal)
{
WaterMammal mammal = (WaterMammal)obj; // e.g. a whale
// Pull mammals fins using all your strength
// Swim as fast as you can
}
.
Logic
duplication,
but no true
code duplication!
Animal obj = ...
if (obj is Mammal)
{
Mammal mammal = (Mammal)obj; // e.g. a tiger
// Pull mammals tail using all your strength
// Run as fast as you can
}
else if (obj is WaterMammal)
{
WaterMammal mammal = (WaterMammal)obj; // e.g. a whale
// Pull mammals fins using all your strength
// Swim as fast as you can
}
.
Applying Object Composition to Build Rich Domain Models
Applying Object Composition to Build Rich Domain Models
Applying Object Composition to Build Rich Domain Models
Applying Object Composition to Build Rich Domain Models
Applying Object Composition to Build Rich Domain Models
Applying Object Composition to Build Rich Domain Models
Applying Object Composition to Build Rich Domain Models
Applying Object Composition to Build Rich Domain Models
Applying Object Composition to Build Rich Domain Models
Applying Object Composition to Build Rich Domain Models
Applying Object Composition to Build Rich Domain Models
Watch the webinar recording here:
https://www.postsharp.net/blog/we
binar-recording-object-composition
Applying Object Composition to Build Rich Domain Models
Applying Object Composition to Build Rich Domain Models
Applying Object Composition to Build Rich Domain Models
Applying Object Composition to Build Rich Domain Models
Applying Object Composition to Build Rich Domain Models
Applying Object Composition to Build Rich Domain Models
Applying Object Composition to Build Rich Domain Models
Applying Object Composition to Build Rich Domain Models
Applying Object Composition to Build Rich Domain Models
Watch the webinar recording here:
https://www.postsharp.net/blog/we
binar-recording-object-composition
Animal Classification Environment Abilities
Animal Classification Environment Abilities
Mammal Ground Walk, Run
Animal Classification Environment Abilities
Mammal Ground Walk, Run
Mammal Ground Walk, Run
Animal Classification Environment Abilities
Mammal Ground Walk, Run
Mammal Ground Walk, Run
Bird Ground Walk, Run
Bird Ground Walk, Run
Animal Classification Environment Abilities
Mammal Ground Walk, Run
Mammal Ground Walk, Run
Bird Ground Walk, Run
Bird Ground Walk, Run
Reptile Ground Walk
Animal Classification Environment Abilities
Mammal Ground Walk, Run
Mammal Ground Walk, Run
Bird Ground Walk, Run
Bird Ground Walk, Run
Reptile Ground Walk
Gastropod Ground Walk (?)
Animal Classification Environment Abilities
Mammal Ground Walk, Run
Mammal Ground Walk, Run
Bird Ground Walk, Run
Bird Ground Walk, Run
Reptile Ground Walk
Gastropod Ground Walk (?)
Mammal SaltWater Surface, Dive, Underwater
Mammal SaltWater Surface, Dive, Underwater
Animal Classification Environment Abilities
Mammal Ground Walk, Run
Mammal Ground Walk, Run
Bird Ground Walk, Run
Bird Ground Walk, Run
Reptile Ground Walk
Gastropod Ground Walk (?)
Mammal SaltWater Surface, Dive, Underwater
Mammal SaltWater Surface, Dive, Underwater
BonyFish SaltWater Underwater, Glide
BonyFish FreshWater Underwater
Animal Classification Environment Abilities
Mammal Ground Walk, Run
Mammal Ground Walk, Run
Bird Ground Walk, Run
Bird Ground Walk, Run
Reptile Ground Walk
Gastropod Ground Walk (?)
Mammal SaltWater Surface, Dive, Underwater
Mammal SaltWater Surface, Dive, Underwater
BonyFish SaltWater Underwater, Glide
BonyFish FreshWater Underwater
Bird Air, Ground Fly, Walk
Bird Air, Ground Fly
Animal Classification Environment Abilities
Mammal Ground Walk, Run
Mammal Ground Walk, Run
Bird Ground Walk, Run
Bird Ground Walk, Run
Reptile Ground Walk
Gastropod Ground Walk (?)
Mammal SaltWater Surface, Dive, Underwater
Mammal SaltWater Surface, Dive, Underwater
BonyFish SaltWater Underwater, Glide
BonyFish FreshWater Underwater
Bird Air, Ground Fly, Walk
Bird Air, Ground Fly
Mammal Ground Walk, Run, Glide
Animal Classification Environment Abilities
Mammal Ground Walk, Run
Mammal Ground Walk, Run
Bird Ground Walk, Run
Bird Ground Walk, Run
Reptile Ground Walk
Gastropod Ground Walk (?)
Mammal SaltWater Surface, Dive, Underwater
Mammal SaltWater Surface, Dive, Underwater
BonyFish SaltWater Underwater, Glide
BonyFish FreshWater Underwater
Bird Air, Ground Fly, Walk
Bird Air, Ground Fly
Mammal Ground Walk, Run, Glide
Mammal Air, Ground Fly
Applying Object Composition to Build Rich Domain Models
Applying Object Composition to Build Rich Domain Models
Applying Object Composition to Build Rich Domain Models
Applying Object Composition to Build Rich Domain Models
Applying Object Composition to Build Rich Domain Models
Applying Object Composition to Build Rich Domain Models
Applying Object Composition to Build Rich Domain Models
Applying Object Composition to Build Rich Domain Models
Double
dispatch
ability.Accept(visitor);
void Run.Accept(AbilityVisitor visitor)
{
visitor.Accept(this); // Accept(Run)
}
Watch the webinar recording here:
https://www.postsharp.net/blog/we
binar-recording-object-composition
Questions?
Zoran Horvat
CEO & Principal Consultant, Coding Helmet Consultancy
zh@sysexpand.com
http://codinghelmet.com
zoranh75

More Related Content

Applying Object Composition to Build Rich Domain Models

  • 1. Applying Object Composition to Build Rich Domain Models Zoran Horvat CEO & Principal Consultant, Coding Helmet Consultancy zh@sysexpand.com http://codinghelmet.com zoranh75
  • 3. Watch the webinar recording here: https://www.postsharp.net/blog/we binar-recording-object-composition
  • 15. Animal obj = ... if (obj is Mammal) { }
  • 16. Animal obj = ... if (obj is Mammal) { Mammal mammal = (Mammal)obj; // e.g. a tiger }
  • 17. Animal obj = ... if (obj is Mammal) { Mammal mammal = (Mammal)obj; // e.g. a tiger // Pull mammals tail using all your strength }
  • 18. Animal obj = ... if (obj is Mammal) { Mammal mammal = (Mammal)obj; // e.g. a tiger // Pull mammals tail using all your strength // Run as fast as you can }
  • 19. Animal obj = ... if (obj is Mammal) { Mammal mammal = (Mammal)obj; // e.g. a tiger // Pull mammals tail using all your strength // Run as fast as you can }
  • 22. Animal obj = ... if (obj is Mammal) { Mammal mammal = (Mammal)obj; // e.g. a tiger // Pull mammals tail using all your strength // Run as fast as you can }
  • 23. Animal obj = ... if (obj is Mammal) { Mammal mammal = (Mammal)obj; // e.g. a tiger // Pull mammals tail using all your strength // Run as fast as you can } else if (obj is WaterMammal) { WaterMammal mammal = (WaterMammal)obj; // e.g. a whale // Pull mammals fins using all your strength // Swim as fast as you can }
  • 24. Animal obj = ... if (obj is Mammal) { Mammal mammal = (Mammal)obj; // e.g. a tiger // Pull mammals tail using all your strength // Run as fast as you can } else if (obj is WaterMammal) { WaterMammal mammal = (WaterMammal)obj; // e.g. a whale // Pull mammals fins using all your strength // Swim as fast as you can }
  • 25. Logic duplication, but no true code duplication! Animal obj = ... if (obj is Mammal) { Mammal mammal = (Mammal)obj; // e.g. a tiger // Pull mammals tail using all your strength // Run as fast as you can } else if (obj is WaterMammal) { WaterMammal mammal = (WaterMammal)obj; // e.g. a whale // Pull mammals fins using all your strength // Swim as fast as you can } .
  • 26. Logic duplication, but no true code duplication! Animal obj = ... if (obj is Mammal) { Mammal mammal = (Mammal)obj; // e.g. a tiger // Pull mammals tail using all your strength // Run as fast as you can } else if (obj is WaterMammal) { WaterMammal mammal = (WaterMammal)obj; // e.g. a whale // Pull mammals fins using all your strength // Swim as fast as you can } .
  • 38. Watch the webinar recording here: https://www.postsharp.net/blog/we binar-recording-object-composition
  • 48. Watch the webinar recording here: https://www.postsharp.net/blog/we binar-recording-object-composition
  • 50. Animal Classification Environment Abilities Mammal Ground Walk, Run
  • 51. Animal Classification Environment Abilities Mammal Ground Walk, Run Mammal Ground Walk, Run
  • 52. Animal Classification Environment Abilities Mammal Ground Walk, Run Mammal Ground Walk, Run Bird Ground Walk, Run Bird Ground Walk, Run
  • 53. Animal Classification Environment Abilities Mammal Ground Walk, Run Mammal Ground Walk, Run Bird Ground Walk, Run Bird Ground Walk, Run Reptile Ground Walk
  • 54. Animal Classification Environment Abilities Mammal Ground Walk, Run Mammal Ground Walk, Run Bird Ground Walk, Run Bird Ground Walk, Run Reptile Ground Walk Gastropod Ground Walk (?)
  • 55. Animal Classification Environment Abilities Mammal Ground Walk, Run Mammal Ground Walk, Run Bird Ground Walk, Run Bird Ground Walk, Run Reptile Ground Walk Gastropod Ground Walk (?) Mammal SaltWater Surface, Dive, Underwater Mammal SaltWater Surface, Dive, Underwater
  • 56. Animal Classification Environment Abilities Mammal Ground Walk, Run Mammal Ground Walk, Run Bird Ground Walk, Run Bird Ground Walk, Run Reptile Ground Walk Gastropod Ground Walk (?) Mammal SaltWater Surface, Dive, Underwater Mammal SaltWater Surface, Dive, Underwater BonyFish SaltWater Underwater, Glide BonyFish FreshWater Underwater
  • 57. Animal Classification Environment Abilities Mammal Ground Walk, Run Mammal Ground Walk, Run Bird Ground Walk, Run Bird Ground Walk, Run Reptile Ground Walk Gastropod Ground Walk (?) Mammal SaltWater Surface, Dive, Underwater Mammal SaltWater Surface, Dive, Underwater BonyFish SaltWater Underwater, Glide BonyFish FreshWater Underwater Bird Air, Ground Fly, Walk Bird Air, Ground Fly
  • 58. Animal Classification Environment Abilities Mammal Ground Walk, Run Mammal Ground Walk, Run Bird Ground Walk, Run Bird Ground Walk, Run Reptile Ground Walk Gastropod Ground Walk (?) Mammal SaltWater Surface, Dive, Underwater Mammal SaltWater Surface, Dive, Underwater BonyFish SaltWater Underwater, Glide BonyFish FreshWater Underwater Bird Air, Ground Fly, Walk Bird Air, Ground Fly Mammal Ground Walk, Run, Glide
  • 59. Animal Classification Environment Abilities Mammal Ground Walk, Run Mammal Ground Walk, Run Bird Ground Walk, Run Bird Ground Walk, Run Reptile Ground Walk Gastropod Ground Walk (?) Mammal SaltWater Surface, Dive, Underwater Mammal SaltWater Surface, Dive, Underwater BonyFish SaltWater Underwater, Glide BonyFish FreshWater Underwater Bird Air, Ground Fly, Walk Bird Air, Ground Fly Mammal Ground Walk, Run, Glide Mammal Air, Ground Fly
  • 69. Watch the webinar recording here: https://www.postsharp.net/blog/we binar-recording-object-composition
  • 70. Questions? Zoran Horvat CEO & Principal Consultant, Coding Helmet Consultancy zh@sysexpand.com http://codinghelmet.com zoranh75