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.
Some rules involve several objects and belong to none of them: transferring money between two accounts, picking the best slot across many doctors’ calendars, pricing a basket with a promotion. Forcing that logic into one entity makes it awkward, so DDD puts it in a domain service, named in the ubiquitous language (“slot matching”, not “BookingHelper”).
It is different from an application service, which only coordinates: loads aggregates, calls the domain, saves and publishes events. The risk is overuse: when every rule ends up in services and entities only hold data, you have an anemic domain model. See the Evans Classification.
Sources
- Martin Fowler: Evans Classification martinfowler.com
Related terms
- 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.
- 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.
- Anemic domain model: Domain objects that only hold data with getters and setters, while all business rules live in service classes around them.
- DDD (domain-driven design): Designing software around the business’s own language and rules, with the code split where that language changes meaning.
