DTOs: best practices

I’ve been reading a few posts here regarding DTO’s and it seems to me that a lot of people equate them to what I would consider a ViewModel. A DTO is just that, Data Transfer Object – it’s what gets passed down the wire. So I’ve got a website and services, only the services will have access to real domain/entity objects, and return DTO’s. These may map 1:1, but consider that the DTO’s may be populated from another service call, a database query, reading a config – whatever.

After that, the website then can take those DTO and either add them to a ViewModel, or convert into one. That ViewModel may contain many different types of DTO’s. A simple example would be a task manager – the ViewModel contains both the task object you are editing, as well as a group of Dto.User objects that the task can be assigned to.

Keep in mind that the services returning DTO’s maybe used by both a website, and maybe a tablet or phone application. These applications would have different views to take advantage of their displays and so the ViewModels would differ, but the DTO’s would remain the same.

At any rate, I love these types of discussions, so anyone please let me know what you think.

Matt

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)