Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Singleton pattern
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Criticism == Some consider the singleton to be an [[anti-pattern]] that introduces [[global variables|global state]] into an application, often unnecessarily. This introduces a potential dependency on the singleton by other objects, requiring analysis of implementation details to determine whether a dependency actually exists.<ref name="google">{{cite web |title=Why Singletons Are Controversial |url=https://code.google.com/archive/p/google-singleton-detector/wikis/WhySingletonsAreControversial.wiki |archive-url=https://web.archive.org/web/20210506162753/https://code.google.com/archive/p/google-singleton-detector/wikis/WhySingletonsAreControversial.wiki |archive-date=6 May 2021 |access-date=28 August 2021 |website=Google Code Archive}}</ref> This increased [[Coupling (computer programming)|coupling]] can introduce difficulties with [[unit testing]].<ref name="button">{{cite news |last1=Button |first1=Brian |date=25 May 2004 |title=Why Singletons are Evil |work=Being Scott Densmore |publisher=Microsoft |url=https://docs.microsoft.com/en-us/archive/blogs/scottdensmore/why-singletons-are-evil |access-date=28 August 2021 |archive-url=https://web.archive.org/web/20210715184717/https://docs.microsoft.com/en-us/archive/blogs/scottdensmore/why-singletons-are-evil |archive-date=15 July 2021}}</ref> In turn, this places restrictions on any abstraction that uses the singleton, such as preventing [[Concurrency_(computer_science)|concurrent]] use of multiple instances.<ref name="button" /><ref>Steve Yegge. [http://steve.yegge.googlepages.com/singleton-considered-stupid Singletons considered stupid], September 2004</ref><ref name="googletesting.blogspot.com">Hevery, Miško, "[http://googletesting.blogspot.com/2008/11/clean-code-talks-global-state-and.html Global State and Singletons]", ''Clean Code Talks'', 21 November 2008.</ref> Singletons also violate the [[single-responsibility principle]] because they are responsible for enforcing their own uniqueness along with performing their normal functions.<ref name="button" />
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)