Domain-Driven Design (50 Qs)•Part 1: Basic & Foundational Concepts (Junior / Entry-Level)
What is an Aggregate and an Aggregate Root?
junior Leveldomain-driven-designBasic
In Simple Words:
- Aggregate: A cluster of associated domain objects (Entities and Value Objects) treated as a single unit for data changes and transactional consistency:
- Example: An
Order(Aggregate Root) containing multipleOrderItementities and aShippingAddressvalue object.
- Example: An
- Aggregate Root: The single master Entity that serves as the only gateway to the aggregate:
- Outside code CANNOT reference or modify internal child entities directly (e.g. code cannot directly modify an
OrderItem). - All operations must pass through methods on the Aggregate Root (
order.addItem(),order.cancel()), allowing the root to enforce business invariants.
- Outside code CANNOT reference or modify internal child entities directly (e.g. code cannot directly modify an