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

Is this a good practice...

 
Bala Krishniah
Ranch Hand
Posts: 81
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The return type of the getBusinessObjects() is 'Object', but I am returning the java.util.Collection, sometimes Hashtable...
Is this a good practice??
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Generally speaking: No.
What is the problem you try to solve?
 
Bala Krishniah
Ranch Hand
Posts: 81
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why would you say its incorrect. Could you please explain.
And the reason I am using the above logic is....
I was reading the database and storing the data, storing is a class object and storing those objects in a Vector and was always returning a Vector from my getBusinessObject() method...
CODE]
Collection getBusinessObject(){}
[/CODE]
But later on, I wanted to return two sets of vector objects from a the getBusinessObject() method. So I thought of putting the vectors in a Hashtable and return it, but couldn't since the return type extected is Collection. I could have added two vectors and returned a single vector...
but then I only have to depend on the position of the object in a vector.
Hence I thought of chaning the return type of getBusinessObject() to Object, so that I can return any type.
Please comment.
 
sandy gupta
Ranch Hand
Posts: 228
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using Vectors causes a lot of overhead and over transferring the same over the wire can be killing. Please try to eliminate the use of Vectors as a means of transferring objects as far as possible. It starts showing once the hit count increases
 
John Smith
Ranch Hand
Posts: 2937
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sandy ind said:

Using Vectors causes a lot of overhead...

I couldn't agree more. We recently did a performance analysis of our app (about 150,000+ lines of code). It turned out that 80% of all the running time was atrributed to a single line of code where an element was searched in a vector. After we replaced the vector with the other collection type (very few lines of code), our app ran 4 times faster (down from 4 minuets to 1)!
Eugene Kononov.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic