Comparison
EntityvsValue object
Entity
two of them with identical fields are still different things, because the thing that makes them the same is the id.
An object defined by a continuous identity rather than by its attributes: a customer who changes name and address is the same customer. Identity is what forces an entity to have a lifecycle, to be tracked, and to be compared by id rather than by value. Getting the entity-or-value question right for each concept is the single highest-leverage modelling decision in this cluster.
Full entry →Value object
two of them with the same contents are interchangeable, so you never update one — you replace it.
An object defined entirely by its attributes, compared by value and, by convention, immutable: money, a date range, a coordinate, an email address. Immutability plus value equality means it can be shared freely, used as a map key and reasoned about without aliasing. Most of the practical benefit of domain modelling comes from making more things value objects, because each one takes a validation rule out of the calling code and puts it somewhere it cannot be skipped.
Full entry →