Introduction to Domain Driven Design

advertisement
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
Continuous
Integration
User
Interface
Database
Domain
Model
Agile
TDD
App Logic
Refactoring
Presentation
View templates
Application
Application Services
Application Logic
AOP
Domain
Domain Services
Domain Logic
Persistence
NHibernate
SPROCS
other
Domain Driven Design
Eric Evans
Applying DDD and Patterns
Jimmy Nilsson










Domain Model
Ubiquitous Language
Entities
Value Objects
Repositories
Services
Aggregate Roots
Supple Design
TDD
Framework Tools





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




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 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 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



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




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




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

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




Very important for refactoring support
Makes you a better programmer!
Serves as model documentation for other
developers
Promotes loose coupling



Initiation
Timing
Makes the model more flexible






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

Strategy Pattern
◦ Encapsulate domain processes

Composite Pattern
◦ Make whole/part domain concepts interchangable

Specification Pattern
◦ Encapsulate specifications within objects for
algorithms
Download