Share
Embed
Transcript
15 slides
-
¡ Anti-‐pattern ¡ Logic outside the model
¡ Copy/paste programming ¡ Recurring bugs -
¡ Domain Driven Design by Eric Evans ¡
Key Concepts § Focus on the business domain § Work with Domain Experts § Create a domain model § Ubiquitous language -
¡ Entities ¡ Value objects ¡ Aggregates/Roots
¡ Services § Repositories § Factories ¡ Specifications -
¡ Immutable (System.String) § Can only be constructed, never
changed § Methods and properties can’t change state § Modifications return new object § Safer especially in multi-‐threaded environments ¡ Mutable (System.Text.StringBuilder) § Methods and properties can change state § Can be faster in practice -
¡ Has an identity (PersonID) ¡ Equality is
based on this identity ¡ Conceptually immutable § Except through public methods § Protects from invalid states Person PersonID Puid Name Email This is my entity, there are many like it, but this one is mine -
¡ Has no concept of identity § Equality
is based on identical state ¡ Should be truly immutable Color Red Green Blue Alpha I see a red door and I want it painted black -
¡ Brings related entities/ values together § Under one
entity ¡ Guarantee consistency ¡ Outside entities can only reference a root ¡ Controls the entire aggregate Order OrderLines Money Address Referral OrderType -
¡ External operations § Entities § Value objects
¡ No state ¡ Takes place of static methods ¡ Specialized implementations § Repositories § Factories -
¡ Responsible for persistence ¡ Only works with
aggregate roots § The entire aggregate must be persisted ¡ Typically uses a database to save state -
¡ Answers a yes/no question § IsSatisfiedBy?
¡ Used when multiple roots interact ¡ Can this student start a contract for Fall 2010? -
¡ Answers questions § Reports § Complicated lists
¡ Low level query ¡ Prevents exponential database queries ¡ Read-‐only objects -
¡ Overly complicated for small projects ¡ Takes
time ¡ Requires domain expert ¡ Difficult to switch gears ¡ Complex business models yield complex domain models -
¡ Distributed Domain Driven Design (DDDD) ¡ Command
Query Responsibility Segregation (CQRS) -
¡ Free eBooks § http://thinkddd.com/ § http://www.infoq.com/minibooks/domain-‐driven-‐ design-‐quickly
¡ Websites § http://www.domaindrivendesign.org/ § http://stackoverflow.com/questions/tagged/ddd § http://elegantcode.com/