What is the difference between VO (Value Object) and DTO (Data Transfer Object)

Asked

Viewed 1,118 times

3

What is the difference between a VO and a DTO, and how to identify when to use each one?

1 answer

6


DTO, as its name says, it is an object with data being transferred between memory and persistence. It is usually a class with all the fields of a model and usually has no behaviors, only state. It can be large and complex and does not usually have identity, that is, if you change something in it, all right, it is still the same object, so typical semantics of reference. For example, a customer or product could be represented at a certain point in the application with the DTO. It is a mechanism objective.

Value Object is something much simpler and represents a unique value, for example a phone, an email, a quantity. It has identity and changes something in it becomes another object, therefore typical semantics of value. In the languages they allow, in fact it is by value and not a class. There are cases that may have behavior.

This may help to understand although it is not the same thing: What’s the difference between Struct and Class?. There is a conceptual relationship between the class and the DTO and the structure and the VO, not that they need to be linked, even because it has language that even has struct.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.