Andy's observations as he continues to attempt to know all that is .NET...

Friday, October 02, 2009

Are Singletons Evil ?

Finally got around to delivering a conference talk on this subject this week at Software Architecture Week, its a topic myself and Kevin Jones are constantly being asked.  Of course a quick google reveals the answer there are numerous rants about this evil pattern.  But like most things in life its not as simple as yes or no. 

Our goal for this talk was to expose the areas were this pattern causes a developer a whole load of pain.  In fact one member of the audience was experiencing such pain in his attempt to take legacy code base heavily utilising singletons and start to write unit tests. 

So whilst the majority of the time was spent examining the consequences of using the singleton pattern we also took time to  highlight that one or two singletons correctly positioned in your application could in fact enable unit testing, and coding to interface without having to refactor large areas of a legacy code base.

This talk took the format of a short geeky play, featuring two developers trying to wrestle with getting the job done and unit testing.  You can download the script and accompanying code

So like all good consultants our answer to this question is “It Depends”

No comments:

About Me

My photo
Im a freelance consultant for .NET based technology. My last real job, was at Cisco System were I was a lead architect for Cisco's identity solutions. I arrived at Cisco via aquisition and prior to that worked in small startups. The startup culture is what appeals to me, and thats why I finally left Cisco after seven years.....I now filll my time through a combination of consultancy and teaching for Developmentor...and working on insane startups that nobody with an ounce of sense would look twice at...