570 likes | 1.11k Views
Introduction to Domain Driven Design. Sean Chambers. About Sean Chambers. Senior Developer at Flagler County Schools Owner Hybrid Software, Educational Software Contributor to various open source projects (Castle Project, Nhibernate, NUnit, NBehave) Practicing TDD,DDD,BDD for 2 years
E N D
Introduction toDomain Driven Design Sean Chambers
About Sean Chambers • Senior Developer at Flagler County Schools • Owner Hybrid Software, Educational Software • Contributor to various open source projects (Castle Project, Nhibernate, NUnit, NBehave) • Practicing TDD,DDD,BDD for 2 years • Blog: http://schambers.lostechies.com • Twitter: schambers
Where does DDD come from? Domain Driven DesignEric Evans Applying DDD and PatternsJimmy Nilsson
Core Concepts • Domain Model • Ubiquitous Language • Entities • Value Objects • Repositories • Services • Aggregate Roots • Supple Design • TDD • Framework Tools
Domain Model • Ditch the Database Driven Design! • OOP Models == Rich Domain Models • Driven by TDD/BDD and Refactoring • Evolves over time/after breakthroughs • NOONE gets it right the first time
The Ubiquitous Language • A shared language used by developers and stakeholders alike • Translation plus risk of misunderstanding is too high of a cost • Use the model as the backbone of the language • Changes to the language, should cause a refactoring to code
Entities (reference objects) • Entities are objects that contain a specific identity in your domain • Long lasting and non-transient, thus need to be persisted to a database for later retrieval • .Equals overload will compare unqiue properties • Contains all logic pertaining to state and all relevant domain logic • Beware anemic domain anti-pattern • No persistence logic!
Value Objects • Value objects are defined by their attributes instead of their identity • Should be immutable, and no identity within domain • Make value objects whole classes that describe simpler Entity classes
Domain Factories • Manages the creation of complex objects in the domain • Client calls Factory, factory then encapsulates complex creation of object and returns • Used for the beginning of an objects lifecycle
Repositories • For each class/aggregate root setup a Repository for in-memory access • Provide add/remove methods for managing persistent objects • Repositories can be DB, XML, Flat file etc.. • Manages the middle and end of an objects lifecycle
Aggregate Roots • Defines explicit boundaries within the domain where complex interaction can be placed behind • Aggregates can only speak/reference with other aggregates • Transient references for single operations only • Simplifies management of complex object graphs
Address Student CourseReg Account Registration Payment Course Location Schedule
Supple Design • Intention Revealing Interfaces • Student.IsRegisteredIn(course) • Registration.PaymentMethodUsed(creditPayment) • Side Effect Free Functions • Command functions • Modification and return functions • Assertions, AKA Design By Contract • Conceptual Contours • Pre-existing areas that aggregates, functions should align • Stand alone classes
TDD • Very important for refactoring support • Makes you a better programmer! • Serves as model documentation for other developers • Promotes loose coupling
Refactoring • Initiation • Timing • Makes the model more flexible
DDD Framework Tools • Caste MonoRail/ASP.NET MVC • NHibernate, Entity Framework, O/R Mappers • Castle Windsor/Spring.NET for DI/IoC • Log4Net/NLog • TeamCity for CI • Nant/MsBuild
Domain Patterns • Strategy Pattern • Encapsulate domain processes • Composite Pattern • Make whole/part domain concepts interchangable • Specification Pattern • Encapsulate specifications within objects for algorithms