Anemic domain model
Domain objects that only hold data with getters and setters, while all business rules live in service classes around them.
Martin Fowler called it an anti-pattern in 2003: the code looks like a domain model, with classes named after business concepts, but behaves like procedures over data structures. Any service can set any field, so nothing protects the invariants, and the same rule gets reimplemented in several services.
It is not always wrong. For a simple domain, an honest transaction script is cheaper than a rich model, and many CRUD areas never need more. The problem is paying for the layers of a domain model (entities, repositories, domain services) and getting none of the protection.
Sources
- Martin Fowler: Anemic Domain Model martinfowler.com
Related terms
- 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.
- Transaction script: One procedure per business operation that reads data, applies the rules and writes the result, with no domain model in between.
- 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.
- Business invariant: A business rule that must be true at all times, such as “a slot cannot be booked twice”, which the model enforces on every change.
