jargon

Comparison

Object equalityvsValue object

Object equality

you put it in a set, put an identical one in, and the set had two of them.

The distinction between two references pointing at the same object and two objects being considered the same value. Getting it wrong is the standard source of duplicated set members, failed map lookups and tests that pass individually; getting it right means overriding equality and the hash together, and only ever on fields that do not change. Entities are compared by identity and value objects by value, which is the whole practical content of that distinction.

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 →

Related comparisons