Saint Singleton: Have We Martyred a Design Pattern Unfairly?
In our book, I wrote the chapter on the Singleton Design Pattern, and on this blog I penned the post entitled, Singletons Give You Pimples. My comments were based on several articles (including one similarly named!) I had read on why to avoid the Singleton and the 2006 OOPSLA meetings in Portland, Oregon. Of the articles available online that detail the problems with the Singleton Miško Hevery’s blog post, Singletons are Pathological Liars is the most detailed, but Scott Densmore’s article, Why Singletons are Evil is an equally convincing—and succinct— argument why we should keep our distance from Singletons.
Even Erich Gamma was quoted as lamenting the fact that they included the Singleton in their Design Pattern book. There’s not a lot more that I can say than I did in my ranting post on Stinkin’ Singletons, and you can find tons more online.
Is There Salvation?
Recently on this blog, my old friend aYo Binite (who got me involved in ActionScript 3.0 design patterns in the first place) suggested that the Singleton wasn’t as bad as I made it out to be. Naturally, I replied with a reasonable argument comparing them to skin-eating viruses, pedophiles, and Nazis. aYo said that the jury was still out, and I wondered, ‘What jury?’ All in all, though, I may have been as unfair to the Singleton as the Roman emperor Diocletian was to Saint Sebastian. (Diocletian first had Sebastian used for archery practice and left him for dead. Then when the emperor found that he had survived—he had Sebastian beaten to death and thrown into a crapper.) Naturally, I don’t want to be equated with the touchy Diocletian, and so I’m offering up an opportunity for comments by our readers to either help pull the Singleton out of the crapper or shoot another arrow into the misguided design pattern. The Comment Section is Open!