• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Using manager objects vs static methods

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
reply
    Bookmark Topic Watch Topic
  • New Topic