Model lookup objects as Entities or Value Objects?

125 views
Skip to first unread message

Naresh Bhatia

unread,
May 10, 2015, 6:59:01 PM5/10/15
to ddd...@googlegroups.com
Example
Entity: Office
{
    officeId: Identifier,
    countryCode: String
    ...
}

Lookup object: Country
Values (persisted in a table):
    { code: "AL", name: "Albania"},
    { code: "AG", name: "Antigua and Barbuda"},
    ...

In this example, the Office entity embeds a country code to describe it's location. Country feels like a value object, it is immutable object, it's a conceptual whole, it is completely replaceable. However value objects shouldn't have an identity, but I am using country code as its identity. What's the right way to think about this?

Other Examples
ExpenseItem embeds an expenseTypeCode
Task embeds a taskTypeCode

Manuel Rascioni

unread,
May 11, 2015, 9:49:47 AM5/11/15
to ddd...@googlegroups.com
Being an Entity or a Value Object isn't absolute.
A Country maybe is an entity in a bounded context, and a value object in another. The same for your examples, when you create a new task type it is an entity, but when you create a Task and assign it a TaskType it is a value object for the Task entity, the task use it as a whole.

Using soft reference you will use just the CountryCode to reference a country in an entity, this is because in your entity you care about just what country is not its internal, that belongs to another context. 

Naresh Bhatia

unread,
May 11, 2015, 10:31:51 AM5/11/15
to ddd...@googlegroups.com
Awesome! Thanks for clarifying, Manuel. So, as I understand it, CountryCode itself is a value (i.e. value object) and that's all the Office entity cares about. Country itself is a entity, perhaps in another bounded context.

oguzh4n

unread,
May 13, 2015, 12:59:10 PM5/13/15
to ddd...@googlegroups.com
http://www.jefclaes.be/2013/05/accidental-entities-you-dont-need-that.html


11 Mayıs 2015 Pazartesi 10:31:51 UTC-4 tarihinde Naresh Bhatia yazdı:

Naresh Bhatia

unread,
May 13, 2015, 3:17:31 PM5/13/15
to ddd...@googlegroups.com
Good read. Thank you!
Reply all
Reply to author
Forward
0 new messages