SteelReed

Search

Search posts, questions…

OOP & DesignQuestion 39 / 42

Middle

What are entities, value objects and aggregates in DDD, and how do you draw aggregate boundaries?

Short answer

An entity has identity (equal when the id is equal); a value object is equal when all its values are equal and should be immutable. An aggregate is a cluster of entities and value objects guarded by an aggregate root: every change goes through the root.

calls only the rootrefers by idOutside codeOrder: aggregate rootOrderLine: entityMoney: value objectCustomer: anotheraggregate

3 points to say:

  1. Entities are equal when the id is equal; value objects when all values are equal, and should be immutable (Money, Address).
  2. An aggregate is a cluster with a root and a consistency boundary; every change goes through the root.
  3. One transaction changes one aggregate; keep aggregates small, refer to others by id, eventual consistency between them.

Keep reading the deep dive

Create a free account to read the full explanation and follow-up questions, mark questions as studied and review them on a schedule.