Data Transfer Object (DTO) or simply Transfer Object is a well- for the transport of 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. In the same way it would be inefficient or even cause errors to pass a more complex entity.
In addition, the data used in the communication often does not accurately reflect the attributes of your model. So a DTO would be a class that provides exactly what is needed for a particular process.
In some cases, DTO or TO is used to map information obtained from the database and then use View (MVC). This is not completely wrong, and you can even optimize the presentation of the data, after all the Controller already receives the information ready to use. However, this can also end up in a heavily polluted model with redundant information.
When I have a well-structured domain, I prefer to create beans that represent this template. These beans are usually called Entities . There, in certain cases (such as certain queries in the views database or having joins ), I create an TO or DTO type to facilitate the transport of this data .
References: