File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

DTO dilemma??

 
Vijay Kashyap
Ranch Hand
Posts: 74
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Regards,
Vijay
 
Kevin Smither
Ranch Hand
Posts: 30
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 74
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kevin,

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

Regards,
Vijay
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic