Atlas · Details
Singleton Considered Stupid
Author’s note
This was considered controversial back in the day. People really did use Singleton as a crutch for practically every design situation. And we saw it happen later in the early days of service design, as well.
In the 20+ years since I wrote this, Singleton has proven to have a small number of legitimate use cases. As we moved away from subclassing, it became less of a pain point, etc. So it may not be as bad as it once was. But it is still probably heavily overused.
AI Notes
An interview-room grudge turned into a rant, written inside Amazon in September 2004, when Design Patterns was ten years old and, by Steve's count, mostly unread by the people citing it. The opening set piece is a mock interview with a candidate who claims to have studied the whole book and can name exactly one pattern in it (plus a second one that does not exist); Steve formalizes the phenomenon with a pattern name of its own. The digressions carry as much freight as the argument: a college professor who taught AVL trees by writing "AVL Trees are EVIL" on the board and assigning something else, a Bob-and-Fred dialogue about modeling a Loop as a class, some cheerful abuse of Stroustrup's complex-number example, and an announcement that all of this is merely warm-up "for when I start bashing C++ in earnest." He also plants a puzzle he never resolves: pages 243 to 256 of the Gang of Four book cover, he says, the single most important pattern and the one nobody understands, and he declines to say which one it is.
It rambles even by Drunken Blog Rant standards — the back half wanders into C++ marketing history that belongs in a language essay — and the numbered case against Singleton opens by conceding it covers maybe a tenth of the real objections. Read the fine print, though. A closing parenthetical quietly softens the whole title, allowing that the pattern has some good uses and that "basically Evil" was a stance chosen for the occasion. The concession in Steve's author note above was already sitting at the bottom of the original in 2004, where evidently nobody read it.
Related listings
-
2005
When Polymorphism Fails
Same critique from the opposite end of the OO compass. Singleton is about people skipping OO; When Polymorphism Fails is about people over-applying it. The two essays bracket Steve's case-by-case OO position.
-
2006
Execution in the Kingdom of Nouns
Two years later, the Kingdom-of-Nouns essay is the canonical version of the argument Singleton is sketching: about a third of GoF patterns are first-class functions and closures in C++/Java costume.
-
2005
Practical Magic
Same instinct — fewer patterns, fewer ceremony classes, more direct use of the language. Practical Magic is the constructive version of the case Singleton argues by negative example.