Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
Niidae Wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Singleton pattern
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
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>
Summary:
Please note that all contributions to Niidae Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Encyclopedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Search
Search
Editing
Singleton pattern
(section)
Add topic