File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Simple DataAccess Design Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Simple DataAccess Design Question" Watch "Simple DataAccess Design Question" New topic

Simple DataAccess Design Question

Hemanth Presingu
Ranch Hand

Joined: Oct 01, 2000
Posts: 30
I am wondering about which design approach to take while passing data between methods.
Let's say i have a class which retrieves 40 values(fields) from a DB and it needs to pass these values to another class.
What is the best way to pass the data.
1. Having get methods for each value.
2. Passing an single dimensional Array with 40 elements.
Each method has it's own advantages and disadvantages.
I am just curious how everyone else is handling this.
Sean MacLean
Ranch Hand

Joined: Nov 07, 2000
Posts: 621
I think the cleanest and most 'oo'-centric way would be to create a 'container' class that represents the the result object. Within this object you could have all your accessor methods. For example, say you're searching the DB for a book. When you find it, do this

Where the Book is a simple class with accessor methods.
This is a very powerful approach and becomes even more so when you want to pass around collections of Books. Hope this helps!
[This message has been edited by Sean MacLean (edited November 09, 2000).]
Hemanth Presingu
Ranch Hand

Joined: Oct 01, 2000
Posts: 30
Thanks for your reply. Your answer looks like a good solution for my requirement.
I agree. Here's the link:
subject: Simple DataAccess Design Question
It's not a secret anymore!