23. Essential Differences
"
"
"
$
$
$
"
"
"
$
$
$
An Order is
something for which
we process Payments!
An Order is
something we ship to
the appropriate
address!
"
"
"
$
$
$
An Order is
something we fulfill
from warehouse
inventory!
24. Bound and Embrace the Differences
Shipping Context
"
"
"
$
$
$
Payments Context
"
"
"
$
$
$
An Order is
something for which
we process Payments!
An Order is
something we ship to
the appropriate
address!
Fulfillment Context
"
"
"
$
$
$
An Order is
something we fulfill
from warehouse
inventory!
37. Tactical Design?
Now it’s time to start speaking the
Ubiquitous Language within each Bounded Context.
■ Business Invariants
■ Policies
■ Transactions
■ State
■ Persistence
38. The Central Concept
Aggregate
A cluster of objects
treated as a single unit.
Often modeled as a
state machine.
The atomic unit for any
transactional
behavior.
Only accessed through its
Root Entity.
Responsible for maintaining
any/all business invariants.
Entity
EntityEntity
Value
Object
Value
Object
Value
Object
44. Order
Business Invariant: “Can only place an order if it contains at least one line item.”
Aggregate
Entity
EntityEntity
Value
Object
Value
Object
Value
Object
Protect business invariants
inside Aggregate boundaries.
Line Item
Place
Order
45. Design Small Aggregates.
Example credit: Vaughn Vernon, Implementing Domain-Driven Design
Large Cluster
Aggregate
SprintRelease
Backlog
Item
Product
(Root)
Multiple
Aggregates
Product
(Root)
Backlog
Item
(Root)
Sprint
(Root)
Release
(Root)
Product ID
"
%
"
%
Aggregate
Entity
EntityEntity
Value
Object
Value
Object
Value
Object
46. Reference Other Aggregates
by Identity Only.
Line Item
Order
(Root)
Product
(Root)
Composition
Product
(Root)
Product IDLine Item
Order
(Root)
Reference
Aggregate
Entity
EntityEntity
Value
Object
Value
Object
Value
Object
48. Domain Event
A Record of a Business-Significant Occurrence
within a Bounded Context.
"$
ग्राहकग्राहक
πελάτηςπελάτης
"$
Aggregate
Aggregate
Aggregate
OrderPlacedEvent
ItemAddedToOrderEvent
OrderCanceledEvent
OrderPaidEvent
OrderFulfilledEvent
OrderDeliveredEvent
49. Application Services
The First Client to Your Domain Model.
Application
Service
Order
{
id: 1
} Place Order
Repository
Find by ID
Place Order