Already I answered about VO.
Entities are all the rest, that is, they are mutable, by reference always, and are usually composed of several other objects, whether Vos or other entities, And something important is that for them to have identity they need an identifier because the object itself has no identity. They exist only because there are other objects to compose it, and a change in some part of its state does not make it another object, it remains the same if the identifier is equal. For all intents and purposes it is the classes that people know in object orientation, but some languages require and in some cases it is necessary that the Vos are classes.
Typical examples are a Customer, a Product, a Invoice. In general the staff not strange much because it is the class that they know, the VO seems somewhat confused because most started learning to program OOP without understanding the fundamental concepts of computing, but they are simple.
One of the criticisms I make for the DDD is that it presupposes a little the technology being used, and one that doesn’t always correspond to reality. It made sense in Java, but for some reason the C# community adopted it, being a language that makes less sense to use DDD. The VO works automatically in C# provided that the person programes properly.
One point that I see as wrong is that people talk about which entity has identity. In fact they don’t, they need an identifier. The object having identity means that its value fully tells what the object is. They even use the right concept, but give a bad name. When you need one value Object specific (the identifier) to give identity to that entity is because the entity as a whole has no identity of its own, needs a ruse to give identity to it.
So in an entity if it has two completely different objects from each other except for the identifier, it’s the same entity. Weird, right? That makes sense for what DDD proposes, and it’s one of the reasons I don’t like.
The part I like about DDD is that having an identifier helps to model in a relational way. Interestingly, the rest doesn’t help. Value objects do not need to be related, they stay within entities in a natural way.
That’s pretty much it. I have read a lot about the subject and each has specific details that vary depending on who is talking, so we can’t say that it has a universal knowledge that goes beyond these basic characteristics.
In summary Vos are used to traffic information between application layers, and entities are used for persistence in the database.
– nullptr
Not only for this. I would say that immutability is the main characteristic of a VO unlike the entity that is mutable. In addition, you may have VO that will not be used to move data between layers and you may also have entities even when you are not using any persistence. It is a basic concept of Entity Relationship Model, more specific to Aggregation x Composition. Eric Evans tried to explain in a more objective way to OOP programmers and decided to give a different name, ended up confusing more!!
– phduarte