DTO

Data Transfer Object (DTO) is an object that helps us to move data between components.

What are the problems about our complex objects?

  • Strong coupling between the client and the domain.
  • Strong coupling between the client and the database.
  • More complexity of the client side.
  • Multiple requests in the same module.
  • Difficulties to serialize.

How can the DTO help us?

It can help us to make a specific object with only the data that we need. Instead of sending an enormous data structure to the client, only we’ll have to send an object with necessary data, just the information that is being needed.

Features:

  • Only an object with necessary attributes.
  • The object can be serializable.
  • It has no business logic.

When do I need to use a DTO?

  • To transfer multiple data in a single request.
  • To simplify the data model for the client.
  • Pass data between code layers.

What are the disadvantages ?

  • We could send more data than we need.
  • We could have many DTO’s and forget what happens to each one.
  • It must require mapping of objects.

Conclusion

DTO's are very useful to manage data layers toward your application or to send data among different applications or services. Only you have to keep on mind don't be excessive with them.