What is an aggregate in DDD?
An Aggregate is a group of related entities and value objects that form a logical whole and are managed as a single unit.
The key parts of an aggregate:
- Aggregate Root: the main entity through which everything inside is accessed.
- Invariants: business rules that must remain true for the whole group.
- Boundaries: everything inside the aggregate changes only through its root.
Example:
The Order aggregate includes OrderItems, but an item can only be changed through Order.add_item().
The point: an aggregate protects data integrity and simplifies managing complex business logic.
Short Answer
Interview readyPremium
A concise answer to help you respond confidently on this topic during an interview.