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!
{{Short description|Design pattern in object-oriented software development}} [[File:Singleton UML class diagram.svg|thumb|A [[class diagram]] exemplifying the singleton pattern.]] In [[object-oriented programming]], the '''singleton pattern''' is a [[software design pattern]] that restricts the [[Instantiation (computer science)|instantiation]] of a [[Class (computer programming)|class]] to a singular instance. It is one of the well-known [[Design Patterns|"Gang of Four" design patterns]], which describe how to solve recurring problems in object-oriented software.<ref name="GoF">{{cite book |author=Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides |url=https://archive.org/details/designpatternsel00gamm/page/127 |title=Design Patterns: Elements of Reusable Object-Oriented Software |publisher=Addison Wesley |year=1994 |isbn=0-201-63361-2 |pages=[https://archive.org/details/designpatternsel00gamm/page/127 127ff] |url-access=registration}}</ref> The pattern is useful when exactly one object is needed to coordinate actions across a system. More specifically, the singleton pattern allows classes to:<ref>{{cite web |title=The Singleton design pattern - Problem, Solution, and Applicability |url=http://w3sdesign.com/?gr=c05&ugr=proble |access-date=2017-08-16 |website=w3sDesign.com}}</ref> * Ensure they only have one instance * Provide easy access to that instance * Control their instantiation (for example, hiding the [[Constructor (object-oriented programming)|constructors]] of a [[Class (computer programming)|class]]) The term comes from the [[Singleton (mathematics)|mathematical concept of a singleton]].
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)