Reputation: 68
In Domain Driven Design(DDD) a ValueObject has the following definition
A Value Object is an object that describes some characteristic or attribute but carries no concept of identity.
Lets say I have 'Client' entity and an 'Order' entity. Orders are related to Clients, so normally I would add field ClientId in the Order class, because I may not reference the Client entity itself. So far so good...
Now I wonder if it is oke to create a value object ClientInfo, which will include the name of the client, the client status, but also the ClientId? ClientInfo would be immutable with only getters for clientName, clientStatus and clientId.
So there you have it, a value object with an entity identifier. Is this against the definition of a value object, or am I safe here?
Upvotes: 3
Views: 2511
Reputation: 12751
A value object with a reference to an entity identifier is fine. If you had two ClientInfo objects with the same information in, they would be completely interchangeable. They are values just like Strings or integers.
Upvotes: 6