1

I think I understand Value Objects ( they have no conceptual identity, set of its attributes is its definition etc) and how they differ from Entities, but I'm still puzzled whether a value of a primitive type ( int, string ...) being assigned directly to property of an Entity is also considered a VO.

For example, in the following code an object ( of type Name ) assigned to Person.Name is a VO, but are values assigned to Person.FirstName, Person.LastName and Person.Age also considered VO?

public class Person
{
    public string FirstName = ...
    public string LastName = ...
    public int Age = ...

    public Name Name = ...
               ...
} 

public class Name
{
    public string FirstName = ...
    public string LastName = ...
    public int Age = ...
}

thank you

user1483278
  • 929
  • 1
  • 9
  • 17
  • It depends. I'd say that First/LastName might end up in the Name VO, while Age would be represented in it's own VO. But again, hard to say without a specific context and behavior that would make it valuable. – Yves Reynhout Jul 11 '12 at 21:03

2 Answers2

3

It doesn't matter if a value is a primitive type (such as string or int) or a complex type composed of primitive types (such as Name). What matters is that you think of it as a mere "value" without any identity -- then it is a value object.

The decision to keep it a primitive or wrap it in a class is an implementation detail. Specific types are easier to extend in the future / add functionality than primitive types.

casablanca
  • 69,683
  • 7
  • 133
  • 150
1

Check this related question... Value objects are more an implementation thing that a "conceptual" one... If you think about it, singleton and flyweight pattern are about turning an object with an identity to an value object for optimization purposes... It's also related to choosing to implement something as mutable or immutable. You can always say that Person is immutable, but after a while, you are a "new" person with different attributes. It's an implementation decision, not a domain or conceptual one. (Immutable things tend to be value objects, and the mutable ones identity objects).

Community
  • 1
  • 1
user1494736
  • 2,425
  • 16
  • 8
  • 1
    This actually goes against the essence of domain-driven design. I think you are confusing domain design concepts (such as entities and value objects, which are conceptual tools) with standard design patterns (such as singleton and flyweight, which are implementation tools). – casablanca Jul 12 '12 at 05:30