There is a common question "Entity vs Value Object".
what about OrderType
? Is it also contained in Order aggregation or is
it a Value object? I think it will be a value object. Am I correct?
I would say that OrderType
is an entity but it depends an your domain.
The difference between Value Object
and Entity
is simple:
Value objects are considered the same when all their properties are equal.
When you care only about the attributes and logic of an element of the
model, classify it as a value object. Make it express the meaning of
the attributes it conveys and give it related functionality. Treat the
value object as immutable.
Entities are considered the same when they have the same identity.
When an object is distinguished by its identity, rather than its
attributes, make this primary to its definition in the model. Keep the
class definition simple and focused on life cycle continuity and
identity.
There is a simple “litmus test” for Entities:
If two instances of the same object have different attribute values,
but same identity value, are they the same entity?