Reputation:
Singletons are so often said to be a bad design choice, so how should you design an application when you want to avoid them?
Upvotes: 9
Views: 1933
Reputation: 9495
My 2 cents.
Just design your application in such way that it's realy doesn't matter if it's singleton passed to your object or not.
Consider if you have MySingleton.Instance inside -> that looks bad and you are tightly coupled with this. If you passed MySignleton as a parameter in a method and it's instantiated outside as a MySingleton.Instance or new MySingleton() -> oh well, I still can mock or change it so it doesn't really matter.
Upvotes: 2
Reputation: 3693
you can use concepts such Dependency Injection to inject the services you depend on (basically the singletons you use) to you, instead of providing a global reference to them
Upvotes: 8