u/iknidein r/compsci • Recommends
On “Learn NOT to use the Singleton pattern”
…testing. If you want to test a class that is using a singleton, even for an external resource like you said (maybe a database), you can't easily mock that out.
Dependency injection over global state is usually the way to go. You can still have a "singleton" object without it having to be global state. I recommend watching Google's tech talk here: link to this video…