What is an Aggregate?
In Domain-Driven Design (DDD), an Aggregate is a cluster of domain objects that are treated as a single unit. An aggregate contains one or more entities, where one of them is the Aggregate Root. The aggregate root is the only entity that can be accessed or modified directly from outside the aggregate, ensuring consistency by enforcing business rules across the whole aggregate.
Key points about an aggregate:
-It encapsulates a group of objects that must be treated together to maintain data integrity.
-Operations outside the aggregate must interact through the aggregate root, not its internal entities.
-Aggregates help in organizing and structuring complex domains, ensuring boundaries and consistency in your domain model.
Example:
In an e-commerce system, an Order aggregate might include the order entity, line items, and shipping details, with the Order being the aggregate root. All modifications or queries related to the order are done through the aggregate root.