DTO, VO, Entity
What Is a DTO(Data Transfer Object)?
- DTO means an object used to transfer or move data.
- It is an object(Java Beans) for exchanging data between layers.
- It refers to an object used when data retrieved from a DB is sent to a Service, Controller, and so on.
- It is a pure data object without logic and has only Getter and Setter methods.
What Is a VO(Value Object)?
- VO(Value Object) literally means a value object.
- It guarantees object immutability, meaning the object’s information does not change.
- It may only have Getter methods.
- Values can be set through a constructor, and using the Builder pattern is convenient in this case.
- Even if VO instances have different names, if all their property values are the same, the two instances can be considered the same object.
- For this, a VO must override the
equals() and hashcode() methods of the Object class.
- A VO is judged to be the same object only when all values of the properties(fields) declared inside the VO are equal for each VO object.
- It can have additional properties beyond the columns in a table.
- A BaseVO class that collects common properties for multiple tables(A, B, C) can also be inherited and used.
What Is an Entity?
- An Entity is an object mapped to an actual DB table.
- It means a collection of data.
- It is data that must be stored and managed.
- It refers to concepts, places, events, and similar things.
- It refers to tangible or intangible subjects.
- Each Entity must be distinguished by an ID and must have a unique identifier.
- ID, member number, and so on.
- It must have at least one property.
- Name, address, and so on.
- It is a set of instances that exist persistently.
- It must be information that is necessary and managed in the relevant business domain.
Summary
- DTO is an object used to move data between layers.
- VO is a pure domain object that has values.
- Entity is an object that maps those values to a DB table.
