Please explain mean what are the differences in Value Object and DTO? Is this only naming different?
Actually, it was Martin Fowler, one of the sharpest minds in software development, that coined this DTO term in his book Patterns of Enterprise Application Architecture.
This is somewhat confusing but DTOs are what we use to call VOs. VOs are objects such as java.lang.Integer that hold values (hence value objects). So use the term DTO and forget about the other one.
I suspect that they are still different patterns:
- the motivation behind a VO is to wrap a single discrete value that can be tested for equivalence with another VO of that type
- the motivation behind a DTO is to wrap multiple discrete values so that they can be treated as a single, discrete, first-class object.
The main confusion these days is that the DTO Pattern is commonly implemented using an object referred to as a Value Object or VO. Sun's Transfer Object pattern does this, so a lot of people have used MyValueObject or MyVO as a naming convention when implementing the pattern. Definitely confusing. ;)
Basically, if you want to model data of variant types, you will be using a DTO pattern. If you want to avoid confusion, use a more accurate naming convention such as MyDTO or MyDataTransferObject.
'Value Object' was used by the Java community to mean a DTO.
I'm told that this differs from how some OO communities used the term 'Value Object' (my unreliable memory is that the term was used by some OO communities to refer to Immutable Featherweights, but I'm open to correction on that point).
From what I've read/recall:
DTO is to be used to transfer data (whole chunks of it), so only one object needs to be transferred instead of multiple smaller ones.
VO are objects that only hold a readonly value. The example I've seen used in a book (I though it was Beck) was A money(bag) object. It's created with a value. If money is added, a new instance is returned instead of an updated one.