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

Time:05-06

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,

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?

CodePudding user response:

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

  • Related