Data Transfer Object (DTO) or simply Transfer Object is a widely used design standard in Java for transporting data between different components of a system, different instances or processes of a distributed system or different systems via serialization.
The idea is basically to group a set of attributes into a simple class in order to optimize communication.
In a remote call, it would be inefficient to pass each attribute individually. Similarly it would be inefficient or even cause errors to pass a more complex entity.
Also, often the data used in communication does not exactly reflect the attributes of your model. So, a DTO would be a class that provides exactly what is necessary for a given process.
In some cases, use the DTO or TO to map information obtained from the database and then use in a View (MVC). This is not completely wrong, and can even optimize the presentation of the data, after all the Controller already gets the ready-to-use information. However, this can also end up in a very polluted model with redundant information.
When I have a well structured domain, I prefer to create Beans representing this model. These Beans are usually called Entities. There, in certain cases (as in certain database searches based on views or who possess joins ), create a type of OT or DTO to facilitate the transport of such data.
References:
and Viewmodel, there’s a difference? Difference between DTO and Viewmodel
– Marconi