How to identify if a concept should be represented as a entity or as a value object

114 views
Skip to first unread message

sudarshan

unread,
Feb 24, 2013, 11:31:21 PM2/24/13
to ddd...@googlegroups.com
Hi All,

I am trying to find out what question one must ask during the modelling process to detect if a concept should be modeled as a entity or as a value object.

My current understanding is the below

If in our domain a car engine can be swapped out and put in another car then it has existence of its own (Aggregation) and hence cannot be a Value Object ... However in our domain if the engine cannot be swapped out and hence makes no sense without a car then it can be modeled as a Value Object (Composition). Does this make any sense ? 

Please let me know what you think 

Thanks

Alexey Raga

unread,
Feb 25, 2013, 3:05:31 AM2/25/13
to ddd...@googlegroups.com
One big difference is that an entity has an Id (within the scope of an aggregate), value objects usually don't.

Immutability is another aspect. 
Value objects are often (and preferably) made immutable, they don't have behaviors associated with them, they only carry some value (and that's the reason they are called Value objects).
Entities typically have some behaviors, they do stuff.

So it depends on how you model your engine. If it is just a set of properties describing an engine - then yes, it is probably a value object. You can share it (or not).
If it expose behaviors, encapsulates and mutates its state, produces side-effect, or it needs to have an identity - then I'd say it is an entity.

Bryan Watts

unread,
Apr 30, 2013, 8:24:05 PM4/30/13
to ddd...@googlegroups.com
Value objects have the property that swapping one for another like it goes unnoticed. If you are using a blue pen, you might be just fine with another blue pen. It only matters what, not which.

However, you might have a favorite pen someone gave you as a gift. In that case, it matters which, because you know that pen from every other pen.

The concept that distinguishes the two scenarios is time. Entities have the property of existing across time; identity correlates the "sameness" of things outside of the current instant. Value object "sameness" matters in the current instant only (i.e. blue and blue).
Reply all
Reply to author
Forward
0 new messages