Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Should Data Transfer Objects (DTOs) be used to bind UI too?

My question is simple:

I have a large Data Transfer Object like:

data class Terminal(
  @Expose
  @SerializedName("inspector_code")
  var inspectorCode:String,

  @Expose
  @SerializedName("inspector_id")
  var inspectorId:Long
  [x50]
)

Most of them are used for the business logic, for http requests, transaction verifying,

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

few of them are used for the UI.

Should this type of DTO be used in the presentation layer too ? or i can have a different one and use converters to build a presentation object, does this even exists in mvvm arhitecture?

>Solution :

The DTO should be converted to a local model class. This does remove the coupling of your endpoints and your UI and allows a more flexible architecture.

Translating a DTO can be done in something like a Repository, which in turn uses your datasource that returns the DTO.

Since the question looks to be targeted at Android (Android-mvvm), you can have a look at this guide here as well https://developer.android.com/topic/architecture

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading