Singleton pattern

It is one of the well-known "Gang of Four" design patterns, which describe how to solve recurring problems in object-oriented software.

Additionally, they permit lazy allocation and initialization, whereas global variables in many languages will always consume resources.

A singleton implementation may use lazy initialization in which the instance is created when the static method is first invoked.

[8] In turn, this places restrictions on any abstraction that uses the singleton, such as preventing concurrent use of multiple instances.

[8][9][10] Singletons also violate the single-responsibility principle because they are responsible for enforcing their own uniqueness along with performing their normal functions.

A class diagram exemplifying the singleton pattern.