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.
An entity has an identity that survives changes: a patient is the same patient after changing their phone number. A value object has no identity: 100 PLN is 100 PLN, and to “change” it you replace it with a new one. Typical examples are money with its currency, an email address, a time slot or a postal address. Martin Fowler explains the equality rule.
The practical gain is validation in one place. If a time slot can only be created with an end after its start, no code anywhere can hold an invalid one, and the rule does not have to be repeated in every handler. Value objects are the most useful tactical building block of DDD and the easiest to adopt; they usually live inside an aggregate.
Sources
- Martin Fowler: Value Object martinfowler.com
Related terms
- 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.
- DDD (domain-driven design): Designing software around the business’s own language and rules, with the code split where that language changes meaning.
- Runtime validation (Zod): Checking at run time that data from outside (requests, APIs, files, models) matches the type your code assumes.
- Domain event: A fact the business cares about, named in the past tense (“visit booked”), that other parts of the system can react to without being called directly.
- 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.
