Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Applying Object Composition to Build Rich Domain Models

521 views

Published on

Modern business applications rely heavily on rich domain classes, which in turn rely heavily on polymorphic execution, code reuse and similar concepts.

How can we extend rich domain classes to support complex requirements?

In this presentation, Zoran Horvat will show why an object composition approach is favored over class inheritance when it comes to code reuse and polymorphism.

The presentation covers:

How class inheritance can lead to combinatorial explosion of classes
What the limitations of object composition are
What design patterns help consume composed objects
Techniques for creating rich features on composed objects

Watch the webinar recording here: http://www.postsharp.net/blog/post/webinar-recording-object-composition

Published in: Software
  • Be the first to comment

  • Be the first to like this

Applying Object Composition to Build Rich Domain Models

  1. 1. Applying Object Composition to Build Rich Domain Models Zoran Horvat CEO & Principal Consultant, Coding Helmet Consultancy zh@sysexpand.com http://codinghelmet.com zoranh75
  2. 2. https://pluralsight.com/authors/zoran-horvat zh@sysexpand.com http://codinghelmet.com zoranh75
  3. 3. Watch the webinar recording here: https://www.postsharp.net/blog/we binar-recording-object-composition
  4. 4. Animal obj = ...
  5. 5. Animal obj = ... if (obj is Mammal) { }
  6. 6. Animal obj = ... if (obj is Mammal) { Mammal mammal = (Mammal)obj; // e.g. a tiger }
  7. 7. Animal obj = ... if (obj is Mammal) { Mammal mammal = (Mammal)obj; // e.g. a tiger // Pull mammal’s tail using all your strength }
  8. 8. Animal obj = ... if (obj is Mammal) { Mammal mammal = (Mammal)obj; // e.g. a tiger // Pull mammal’s tail using all your strength // Run as fast as you can }
  9. 9. Animal obj = ... if (obj is Mammal) { Mammal mammal = (Mammal)obj; // e.g. a tiger // Pull mammal’s tail using all your strength // Run as fast as you can }
  10. 10. Animal obj = ... if (obj is Mammal) { Mammal mammal = (Mammal)obj; // e.g. a tiger // Pull mammal’s tail using all your strength // Run as fast as you can }
  11. 11. Animal obj = ... if (obj is Mammal) { Mammal mammal = (Mammal)obj; // e.g. a tiger // Pull mammal’s 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 mammal’s fins using all your strength // Swim as fast as you can }
  12. 12. Animal obj = ... if (obj is Mammal) { Mammal mammal = (Mammal)obj; // e.g. a tiger // Pull mammal’s 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 mammal’s fins using all your strength // Swim as fast as you can }
  13. 13. Logic duplication, but no true code duplication! Animal obj = ... if (obj is Mammal) { Mammal mammal = (Mammal)obj; // e.g. a tiger // Pull mammal’s 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 mammal’s fins using all your strength // Swim as fast as you can } .
  14. 14. Logic duplication, but no true code duplication! Animal obj = ... if (obj is Mammal) { Mammal mammal = (Mammal)obj; // e.g. a tiger // Pull mammal’s 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 mammal’s fins using all your strength // Swim as fast as you can } .
  15. 15. Watch the webinar recording here: https://www.postsharp.net/blog/we binar-recording-object-composition
  16. 16. Watch the webinar recording here: https://www.postsharp.net/blog/we binar-recording-object-composition
  17. 17. Animal Classification Environment Abilities
  18. 18. Animal Classification Environment Abilities Mammal Ground Walk, Run
  19. 19. Animal Classification Environment Abilities Mammal Ground Walk, Run Mammal Ground Walk, Run
  20. 20. Animal Classification Environment Abilities Mammal Ground Walk, Run Mammal Ground Walk, Run Bird Ground Walk, Run Bird Ground Walk, Run
  21. 21. Animal Classification Environment Abilities Mammal Ground Walk, Run Mammal Ground Walk, Run Bird Ground Walk, Run Bird Ground Walk, Run Reptile Ground Walk
  22. 22. 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 (?)
  23. 23. 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
  24. 24. 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
  25. 25. 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
  26. 26. 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
  27. 27. 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
  28. 28. Double dispatch ability.Accept(visitor); void Run.Accept(AbilityVisitor visitor) { visitor.Accept(this); // Accept(Run) }
  29. 29. Watch the webinar recording here: https://www.postsharp.net/blog/we binar-recording-object-composition
  30. 30. Questions? Zoran Horvat CEO & Principal Consultant, Coding Helmet Consultancy zh@sysexpand.com http://codinghelmet.com zoranh75

×