GoF-Singleton Pattern
Details
- Full Name
-
GoF Singleton Pattern (Creational)
Intent:
Ensure a class only has one instance, and provide a global point of access to it.
When to Use:
-
When there must be exactly one instance of a class
-
When the sole instance should be extensible by subclassing
Prompt Example:
"Stelle sicher, dass der ConfigManager als GoF-Singleton implementiert ist, mit thread-sicherem Lazy Loading."
Related Anchors:
-
GoF Design Patterns (Umbrella)
Criticism:
-
Erich Gamma, co-author of the original GoF book, said in the 2009 interview "Design Patterns 15 Years Later" (InformIT, Larry O’Brien) that he favours dropping Singleton from the pattern catalog: "Its use is almost always a design smell"
-
Miško Hevery, "Singletons are Pathological Liars" (Google Testing Blog, 2008) — Singletons hide dependencies from the API surface and make code hard to test in isolation
-
Widely categorised as an anti-pattern in modern practice: it introduces global mutable state, couples consumers to a concrete class, and complicates concurrency and test isolation — dependency injection of a single instance is the commonly recommended alternative