Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

where should I do the conversion: Domain object<->DTO?

In Domain Layer or Data access layer?

like image 386
Benny Avatar asked Mar 13 '10 12:03

Benny


1 Answers

The primary motivation for DTOs is to present an interface tailored to another layer (typically, the presentation layer). For example, a data entry screen may need some bits of data from a User object in addition to some bits from an Order, etc. In that case, the Domain to DTO should happen at the layer which the presentation layer invokes, i.e., typically a "service" layer.

There are libraries like Dozer out there which automate the grunt work of converting between domain models and DTOs.

The key take away is DTOs are meant to abstract the data (not business logic) out of richer domain model objects - hence, DTOs should be converted back to domain objects as early as possible (at service layer) so the rest of your application layers may work with richer domain objects (data and business logic)

like image 60
JijoeV Avatar answered Jan 01 '23 02:01

JijoeV