Meaningless Drivel is fun!
The moose likes Java in General and the fly likes Using manager objects vs static methods Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Using manager objects vs static methods" Watch "Using manager objects vs static methods" New topic

Using manager objects vs static methods

Randy Johnson

Joined: Apr 17, 2002
Posts: 22
In an object-relational mapping model, one would have an instance of an object mapped to a row in a relational table. To manage a collection of instances, a separate object manager instance could be created to: get a list of instances, save a list of instances, etc.
An alternative would be to use static methods at the instance's class level to perform the same management functions.
What are the advantages/disadvantages to each approach? It seems like static methods would cut down on object clutter, but do they perform well in a high volume, multi-user environment? Is there a potential bottleneck issue with multiple users accessing the same static methods?
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Static methods have some issues with flexibility. When you say SomeClass.method() you're committed to SomeClass. We can't easily slip you a subclass or another implementation of an interface for custom behavior. If you say

then the factory can return a list manager for databases or one for XML web services, or one for flat files, or one that works all in memory for unit testing.

And, yes, static methods that use static variables can have thread issues. If they only use local variables they can be made safe ... or not.

Performance is generally not a consideration in deciding when to use static methods. Other design factors, like the flexibility shown above, are much more important.

Hope that helps!

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
I agree. Here's the link:
subject: Using manager objects vs static methods
It's not a secret anymore!