QuanticDev
QuanticDev copied to clipboard
Singleton pattern might become an anti-pattern if mis or over used
Critics consider the singleton to be an anti-pattern in that it is frequently used in scenarios where it is not beneficial, introduces unnecessary restrictions in situations where a sole instance of a class is not actually required, and introduces global state into an application.
src: https://en.wikipedia.org/wiki/Singleton_pattern
I have the sentence Remember that this makes testing harder!
at the explanation but it could be enforced with the quote from wiki above.
Obviously, if you want global state, singleton is still valid while there are other options according to situation in hand.
Also incorporate other feedback from the discussion thread on Reddit: https://www.reddit.com/r/programming/comments/eej3ro/software_design_patterns_principles_and_best/