applying object composition to build rich domain models
TRANSCRIPT
Applying Object Composition to Build Rich Domain Models
Zoran HorvatCEO & Principal Consultant, Coding Helmet Consultancy [email protected] http://codinghelmet.com zoranh75
https://pluralsight.com/authors/zoran-horvat
[email protected] http://codinghelmet.com zoranh75
Watch the webinar recording here:
https://www.postsharp.net/blog/webinar-recording-object-composition
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 mammal’s tail using all your strength}
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}
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}
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}
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}
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}
Logicduplication,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}
.
Logicduplication,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}
.
Watch the webinar recording here:
https://www.postsharp.net/blog/webinar-recording-object-composition
Watch the webinar recording here:
https://www.postsharp.net/blog/webinar-recording-object-composition
Animal Classification Environment
Abilities
Animal Classification Environment
Abilities
Mammal Ground Walk, Run
Animal Classification Environment
Abilities
Mammal Ground Walk, RunMammal Ground Walk, Run
Animal Classification Environment
Abilities
Mammal Ground Walk, RunMammal Ground Walk, Run
Bird Ground Walk, RunBird Ground Walk, Run
Animal Classification Environment
Abilities
Mammal Ground Walk, RunMammal Ground Walk, Run
Bird Ground Walk, RunBird Ground Walk, Run
Reptile Ground Walk
Animal Classification Environment
Abilities
Mammal Ground Walk, RunMammal Ground Walk, Run
Bird Ground Walk, RunBird Ground Walk, Run
Reptile Ground WalkGastropod Ground Walk (?)
Animal Classification Environment
Abilities
Mammal Ground Walk, RunMammal Ground Walk, Run
Bird Ground Walk, RunBird Ground Walk, Run
Reptile Ground WalkGastropod Ground Walk (?)Mammal SaltWater Surface, Dive,
UnderwaterMammal SaltWater Surface, Dive,
Underwater
Animal Classification Environment
Abilities
Mammal Ground Walk, RunMammal Ground Walk, Run
Bird Ground Walk, RunBird Ground Walk, Run
Reptile Ground WalkGastropod Ground Walk (?)Mammal SaltWater Surface, Dive,
UnderwaterMammal SaltWater Surface, Dive,
UnderwaterBonyFish SaltWater Underwater, GlideBonyFish FreshWater Underwater
Animal Classification Environment
Abilities
Mammal Ground Walk, RunMammal Ground Walk, Run
Bird Ground Walk, RunBird Ground Walk, Run
Reptile Ground WalkGastropod Ground Walk (?)Mammal SaltWater Surface, Dive,
UnderwaterMammal SaltWater Surface, Dive,
UnderwaterBonyFish SaltWater Underwater, GlideBonyFish FreshWater Underwater
Bird Air, Ground Fly, WalkBird Air, Ground Fly
Animal Classification Environment
Abilities
Mammal Ground Walk, RunMammal Ground Walk, Run
Bird Ground Walk, RunBird Ground Walk, Run
Reptile Ground WalkGastropod Ground Walk (?)Mammal SaltWater Surface, Dive,
UnderwaterMammal SaltWater Surface, Dive,
UnderwaterBonyFish SaltWater Underwater, GlideBonyFish FreshWater Underwater
Bird Air, Ground Fly, WalkBird Air, Ground Fly
Mammal Ground Walk, Run, Glide
Animal Classification Environment
Abilities
Mammal Ground Walk, RunMammal Ground Walk, Run
Bird Ground Walk, RunBird Ground Walk, Run
Reptile Ground WalkGastropod Ground Walk (?)Mammal SaltWater Surface, Dive,
UnderwaterMammal SaltWater Surface, Dive,
UnderwaterBonyFish SaltWater Underwater, GlideBonyFish FreshWater Underwater
Bird Air, Ground Fly, WalkBird Air, Ground Fly
Mammal Ground Walk, Run, GlideMammal Air, Ground Fly
Doubledispatch
ability.Accept(visitor);
void Run.Accept(AbilityVisitor visitor){ visitor.Accept(this); // Accept(Run)}
Watch the webinar recording here:
https://www.postsharp.net/blog/webinar-recording-object-composition
Questions?
Zoran HorvatCEO & Principal Consultant, Coding Helmet Consultancy [email protected] http://codinghelmet.com zoranh75