File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes OO, Patterns, UML and Refactoring and the fly likes DTO dilemma?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "DTO dilemma??" Watch "DTO dilemma??" New topic

DTO dilemma??

Vijay Kashyap
Ranch Hand

Joined: Jul 30, 2001
Posts: 74
Hi All,

I have a situation where a data transfer object(DTO) used between Service layer and web layer holds a number of java.util.List's. But the type of object in the list will change depending upon data transfer direction.

For example List will hold object of Type ClassA when Web layer is using the DTO populated by Service Layer but it will hold object of Type ClassB when Service layer is using the DTO populated by Web Layer.

I know that this won't work if I use Generics (1.5) but as I am not using 1.5 is this looks ok from architecture point? Or should I define 2 different DTO's for this.

Kevin Smither
Ranch Hand

Joined: Oct 22, 2007
Posts: 30
If I get this right you're using the same DTO to return the result of some Service API as the parameter to that Service API?

Something like this:
public MyDTO myServiceAPI(MyDTO dto);

where 'dto' has a List of ClassB populated by Web tier and the return MyDTO has List of ClassA populated by Service tier, correct?

That re-use does not seem proper to me, it's better to separate the DTOs out as example: serviceParamDTO, serviceResultDTO etc. so that it improves clarity and provides separation. Then you can also use generics to strongly type the Lists.

Always favor strong typing whenever possible
Vijay Kashyap
Ranch Hand

Joined: Jul 30, 2001
Posts: 74

Thanks for the reply. Well I am going with 2 DTO's for clarity sake, as mentioned by you.

I agree. Here's the link:
subject: DTO dilemma??
Similar Threads
Implementing Patterns
Difference between DTO and ActionForm
Using DAO in struts
domain objects as DTO's