Hi,
'country': Value Object or Entity in DDD?
Opinions either way appreciated.
And, where to store the table of country names/codes? DB? XML? In a class?
Thanks!
Hi,
'country': Value Object or Entity in DDD?
Opinions either way appreciated.
And, where to store the table of country names/codes? DB? XML? In a class?
Thanks!
If your domain is geographic or political, then it might be an entity, but in the average case, a country is just a value associated with things like addresses. In that case, in the context of your object model, it's just a value.
As for storage, the domain model doesn't really care. You can use the database if it's convenient, XML if you prefer, and a class if you have behavior associated with countries.
One of the characteristics of an entity is that it has a life cycle, i.e. it changes over time. A value object does not. In fact, value objects should be immutable. So the question to ask yourself is, "Does the country object change over time?"
Another aspect which differentiates entities and value objects is that two value objects with the same properties are the same. So if you have an instance of country with the name "France", it's the same as another instance of country with the name "France", even though they are two distinct instances (assuming that's the only property of country for the sake of this discussion). Think of strings in most languages, the string "fubar" equals another instance of the string "fubar".
Entities, on the other hand, are distinct even if they have the same properties. One customer with the name "John Smith" may not be the same as another customer with the name "John Smith".
So given these characteristics you should be able to decide. Since there can be only one "France" and it doesn't change over time, it's probably a value object - unless your app needs to track more about a country which may change over time.
Imagine:
You have another entity - Customer.
Customer entity references Country object.
You have 2 entity instances with filled Country objects with same value (i.e. "France")
You are deleting country object from first entity (or first entity object)