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 Is this a good practice... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Is this a good practice..." Watch "Is this a good practice..." New topic

Is this a good practice...

Bala Krishniah
Ranch Hand

Joined: Dec 14, 2000
Posts: 81
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

Joined: Jul 11, 2001
Posts: 14112
Generally speaking: No.
What is the problem you try to solve?

The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Bala Krishniah
Ranch Hand

Joined: Dec 14, 2000
Posts: 81
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...
Collection getBusinessObject(){}
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

Joined: Jan 30, 2001
Posts: 228
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

Joined: Oct 08, 2001
Posts: 2937
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:
subject: Is this a good practice...
It's not a secret anymore!