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.
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
Joined: Jul 30, 2001
Thanks for the reply. Well I am going with 2 DTO's for clarity sake, as mentioned by you.