Aggregate Root
An “Aggregate Root” is a concept of Domain Driven Design that describes the main entity (“root”) of a graph of nested objects.
Classic example: a Customer
entity might be associated with multiple Order
s in a shop system, and an Order
references many LineItem
s or Product
s.
-
In terms of the Bounded Context of “making an order”, the
Order
can be the aggregate root: aPendingOrder
referencesLineItem
s, which areProduct
references + their quantities + bulk discounts. ThePendingOrder
groups, or: “aggregates”, all these info. -
In terms of the Bounded Context of “listing all previous orders”, the
Customer
object is the Aggregate Root with all its associatedOrder
s and maybe evenPendingOrder
s that await payment or represent a shopping basket.
So: