Possible Duplicate:
What is so bad about Singletons?
Singleton Design Pattern: Pitfalls
I hear a lot of this but din't find firm reason for it.
Avoid the singleton anti-pattern and replace it with DI.
but, why?
Possible Duplicate:
What is so bad about Singletons?
Singleton Design Pattern: Pitfalls
I hear a lot of this but din't find firm reason for it.
Avoid the singleton anti-pattern and replace it with DI.
but, why?
Stateful singletons are much more difficult to unit test.
I use stateless singletons which I don't see a problem with.
Since singletons can implement interfaces, they can be passed using dependency injection (and should be passed as such where possible)
Marshaller interface which functionally turns an Object into a byte[] and back again. You want to be able to pass different strategies via DI which means you have to have an instance to pass. There is any number of implementations for this each potentially with their own class, but you only need one instance if they are stateless.