Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using manager objects vs static methods

 
Randy Johnson
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • 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?
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • 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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic