Entity (DDD)
A domain object with its own identity that stays the same while its data changes, such as a patient, an order or a doctor’s profile.
Eric Evans sorted domain objects into three kinds, which Martin Fowler calls the Evans Classification: entities, value objects and domain services. An entity is tracked by an identifier, not by its attributes: two patients with the same name are still two patients, and one patient who changes their address is still the same one.
In practice most entities live inside an aggregate, and only the aggregate root is loaded and saved through a repository. A common mistake is making everything an entity with an ID and setters; many things (money, a time slot, an address) are better modeled as value objects.
Sources
- Martin Fowler: Evans Classification martinfowler.com
Related terms
- Value object: A small immutable object defined only by its values, like money or a date range; two with the same values are the same thing.
- Aggregate (DDD): A cluster of objects changed as one unit, with a single root that enforces the business rules and marks the boundary of one transaction.
- Domain service: A stateless operation with business meaning that does not naturally belong to one entity, such as matching a patient to an available slot.
- Repository pattern: An object that looks like an in-memory collection of aggregates (add, find by ID, remove) and hides how they are stored.
