File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Best way to transport 2 different type of objects Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Best way to transport 2 different type of objects" Watch "Best way to transport 2 different type of objects" New topic
Author

Best way to transport 2 different type of objects

Cesar Coz
Ranch Hand

Joined: Aug 19, 2010
Posts: 32
like the name of this topic, i'm looking for the best way to transport a container with 2 different type of data.. let's say 2 Beans or DTO's between layers in an application
i'm thinking in 2 options:

1) create a generic 'ArrayList' (with the type undefined) and put the first DTO in the 0 location and the second DTO in the 1 location

2) create a 'Map' (also with the type undefined) and put both DTO's there

maybe there's a better way to do this. hope someone could help me


Cesar Coz.
Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2853
    
  11

The best way is to define a method in the target layer of your application that takes two parameters of the type you want to transport to it. Can you show why that's impractical in your case? A more specific definition of what you mean by transport would help as well.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Agreed--why lose type safety when you don't have to?
Cesar Coz
Ranch Hand

Joined: Aug 19, 2010
Posts: 32
well i have 2 different types of data containers (java Beans) and i need them both in an action... and i wanted to call both of them at the same time
anyone knows how to make a 'multiple return' method or maybe just storing both Beans in another object and transport that object will solve it?

i want to implement the best practice
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

Look at the refactoring "Introduce Parameter Object". From Refactoring, Improving the design of existing code by Martin Fowler.


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Best way to transport 2 different type of objects