This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Simple DataAccess Design Question

 
Hemanth Presingu
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
-Hemanth
 
Sean MacLean
author
Ranch Hand
Posts: 621
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
Sean
[This message has been edited by Sean MacLean (edited November 09, 2000).]
 
Hemanth Presingu
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply. Your answer looks like a good solution for my requirement.
-Hemanth
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic