QuanticDev icon indicating copy to clipboard operation
QuanticDev copied to clipboard

Singleton pattern might become an anti-pattern if mis or over used

Open soygul opened this issue 5 years ago • 0 comments

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/

soygul avatar Dec 23 '19 15:12 soygul