Qcon DDD Clean
Qcon DDD Clean
the
Domain
Interaction
With Model a
Domain single
Experts Sub-Domain
at a time
Purchase Materials
Engineering
Sales
Accounting
Marketing
Manage Employees
Interaction
With Model a
Domain single
Experts Sub-Domain
at a time
Implementation
of
Sub-Domains
Software implementation
Communication
Development
Process
Modeling
Drawbacks of DDD
Time and Effort
Discuss & model the problem with domain expert
Isolate domain logic from other parts of application
Learning curve (why you’re watching this course)
New principles
New patterns
New processes
Only makes sense when there is complexity in the problem
Not just CRUD or data-driven applications
Not just technical complexity without business domain complexity
Team or Company Buy-In to DDD
Software implementation
ENTITIES
MODEL- a AGGREGATES
VALUE
DRIVEN OBJECTS
DESIGN
Communication
UBIQUITOUS
LANGUAGE
BOUNDED
CONTEXT
Modeling
ANTI-
CORRUPTION
LAYER
bit.ly/PS-DDD
2013
2006
2003
2014
D
is for
DOMAIN
Domain Experts
are your
Partners
from start to finish of project
Domain Modeling
But Where Is the Database?
Creative Commons
Insulate Bounded Contexts
Bounded
Context
Bounded
Context
Legacy
App
ACLs Between Bounded Contexts, Too
Translate
between
foreign systems’ models & our own
using
Design patterns, e.g. : Façade, Adapter
or custom translation classes or services
Even when the other system is well
designed, it is not based on the same
model as the client.
—Eric Evans
Domain-Driven Design
The structure of an Anti-Corruption Layer
—Eric Evans
Domain-Driven Design Thinking
UI Can “Link" Different Bounded Contexts
Aggregates
Product Aggregate
Product
Component
Aggregates
in the
Navigation Map
AGGREGATES
Evans,
Domain-Driven Design, p. 65
FOCUS ON
Behaviors
Schedule an appointment for a checkup
Note a pet’s weight
Request lab work
Notify pet owner of vaccinations due
Accept a new patient
Book a room
Not Attributes
Appointment.Time Pet.Name Owner.Telephone Room.Number
Team Exercise
Select some of the bounded contexts
Within that B.C. what entities belong together in an aggregate?
What is the aggregate root?
Why?
Rich
Domain
Anemic Models
Domain Models
Rich Domain Models over Anemic Types
Anemic for CRUD Rich for DDD
private
private
Entities
in the
Navigation Map
ENTITIES
Evans,
Domain-Driven Design, p. 65
Entities in the Appointment Scheduling Context
Relationships
A bidirectional association means that both objects can
be understood only together. When application
requirements do not call for traversal in both directions,
adding a traversal direction reduces interdependence
and simplifies the design.
—Eric Evans
Start with One-Way Relationships
Uni-Directional Associations
Doctor
Appointment Patient
Client
Client Patient
VALUE OBJECTS
Value Object
ü Measures, quantifies, or describes a thing in the
domain.
ü Identity is based on composition of values
ü Immutable
ü Compared using all values
ü No side effects
String: Our Favorite Value Object
SCAR
T
“Boots” lives with Pluralsight author, Lars Klint
?
Company Worth: $50,000,000
? $ 50,000,000
?Company (Entity)
ID (guid): 9F63CE8D-9F1E-45E0-85AB-C098CC15F8E6
Worth Unit (string): “Canadian Dollar”
Worth Amount (decimal): 50000000
Company (Entity)
ID (guid): 9F63CE8D-9F1E-45E0-85AB-C098CC15F8E6
{
Worth (Value Object)
Worth Monetary Unit (string) “Canadian Dollar”
Amount (decimal): 50000000
Source:http://fit.c2.com/wiki.cgi?WholeValue (Ward Cunningham)
Patient Appointment
10:00 am Jan 4, 2014 – 11:00 am Jan 4, 2014
Staff Meeting
2:00 pm Feb 1, 2014 – 3:15 pm Feb 1, 2014
public class DateTimeRange
{
public DateTimeRange(DateTime start, DateTime end)
{
Start=start;
End=end;
}
public DateTime Start { get; private set; }
public DateTime End { get; private set; }
…
}
It may surprise you to learn that we should strive
to model using Value Objects instead of Entities
wherever possible. Even when a domain concept
must be modeled as an Entity, the Entity’s design
should be biased toward serving as
a value container rather than a child Entity
container.
—Vaughn Vernon
Implementing Domain Driven Design
Our DateTimeRange Value Object
Team Exercise
Pick same Bounded Context you used for aggregate root
What behaviors need to happen within there
Can you justify 1:1 relationships or are they better as value objects?
Can you justify bi-directional relationshps or are they better as uni-directional
Model some of the methods
Resources
§ Domain-Driven Design Fundamentals on Pluralsight bit.ly/PS-DDD
§ All of my Pluralsight courses: pluralsight.com/author/julie-lerman
§ Domain-Driven Design, Eric Evans amzn.to/1kstiRg
§ Implementing Domain-Driven Design, Vaughn Vernon amzn.to/1dgYRY3
§ Domain Modeling with Entity Framework Scorecard, Jimmy Bogard, bit.ly/1x925bu
§ Coding for Domain-Driven Design: Tips for Data-Focused Devs (3 Parts)
MSDN Magazine, Aug, Sept& Oct 2013 bit.ly/15xMlDL
§ CQRS Journey from MS Patterns & Practices: bit.ly/cqrsjourney
§ A Pattern for Sharing Data Across Domain-Driven Design Bounded Contexts (Part 1&2)
MSDN Magazine, Oct & Dec 2014: bit.ly/DataPoints_Dec2014
§ Entity Framework Model Partitioning in Domain-Driven Design Bounded Contexts
TechEd Europe 2014: bit.ly/TEE2014_EFDDD