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

Best way to transport 2 different type of objects

 
Cesar Coz
Ranch Hand
Posts: 32
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Greg Charles
Sheriff
Posts: 2984
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Agreed--why lose type safety when you don't have to?
 
Cesar Coz
Ranch Hand
Posts: 32
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2700
IntelliJ IDE Opera
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at the refactoring "Introduce Parameter Object". From Refactoring, Improving the design of existing code by Martin Fowler.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic