Object Aggregate
- Definition
- An aggregate is a cluster of objects that can be treated as a single unit. One of these objects is the root
How does it work?
"A DDD aggregate is a cluster of domain objects that can be treated as a single unit. An example may be an order and its line-items, these will be separate objects, but it's useful to treat the order (together with its line items) as a single aggregate.
An aggregate will have one of its component objects be the aggregate root. Any references from outside the aggregate should only go to the aggregate root. The root can thus ensure the integrity of the aggregate as a whole." - Martin Fowler
Examples
- Order and line items
When should you use it?
- When different processes should not modify part of the aggregate simultaneously, because it would corrupt its integrity