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!
== Common uses == Singletons are often preferred to [[global variables]] because they do not pollute the global [[namespace]] (or their containing namespace). Additionally, they permit [[Lazy evaluation|lazy]] allocation and initialization, whereas global variables in many languages will always consume resources.<ref name="GoF" /><ref name="devin">{{cite news |last1=Soni |first1=Devin |date=31 July 2019 |title=What Is a Singleton? |work=BetterProgramming |url=https://betterprogramming.pub/what-is-a-singleton-2dc38ca08e92 |access-date=28 August 2021}}</ref> The singleton pattern can also be used as a basis for other design patterns, such as the [[Abstract factory pattern|abstract factory]], [[Factory method pattern|factory method]], [[Builder pattern|builder]] and [[Prototype pattern|prototype]] patterns. [[Facade pattern|Facade]] objects are also often singletons because only one facade object is required. [[Log file|Logging]] is a common real-world use case for singletons, because all objects that wish to log messages require a uniform point of access and conceptually write to a single source.<ref name="rainsberger">{{cite news |last1=Rainsberger |first1=J.B. |title=Use your singletons wisely |url=https://www.ibm.com/developerworks/library/co-single/ |access-date=28 August 2021 |publisher=IBM |date=1 July 2001 |archive-url=https://web.archive.org/web/20210224180356/https://www.ibm.com/developerworks/library/co-single/ |archive-date=24 February 2021}}</ref>
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)