“Some objects are not defined primarily by their attributes. They represent a thread of identity that runs through time and often across distinct representations… An object defined primarily by its identity is called an ENTITY” (Evans, 91)
Value objects as IDs
Value objects may be preferable to use as a type of ID property of the entity. For example, instead of:
use this instead:
It can help with:
- refactoring
- guarding from invalid entities
- help to catch bugs, when, for example, ID of the
Order
is passed to a method instead of an ID of theProduct
, and the static analyzer couldn’t catch it because they both have aUUID
orstr
type that is expected by method.
Read more on that: