views:

104

answers:

3

Possible Duplicate:
What's Alternative to Singleton

If I am not allowed to use the Singleton pattern because it is not good OOP, what are my options? I often have a lot of stuff that needs quick access. If I use a Singleton I am told it is not good OOP, and if I reference the stuff I get a lot of classes with to much references.

Any idéas?

+4  A: 

Consider using Inversion of Control via Dependency Injection. This can often be used in many places where people reach for Singletons.

Reed Copsey
+1  A: 

"It isn't good OOP" is not a good reason to reject a coding pattern. OOP is good for certain things, but most definitely not for all things.

I'm not a big fan of Singleton myself, tbh, but not because it's "not good OOP", but rather because it has many of the same drawbacks as global variables, plus extra object gunk. I'd have to know more about the structure of your application to give advice on what to use instead, though.

Zack
A: 

You could always go to a more service oriented approach and host a service that could defined as a Singleton to process various work items for multiple callers...

[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)] 
public class MySingleton : 
{
}
fdfrye