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:
Post a Comment