As with many developers, I’ve flirted a lot with Uncle Bob Martin‘s SOLID principles, and honestly believe they have helped me build far more scalable and serviceable code than I would have written otherwise.
Now, there are many articles, examples and projects on SOLID already on the web, so I don’t want waste too much time repeating everything here, simply for the sake of a blog post (though it’s possible I will discuss them all sometime or another). Instead, in these posts, I want to talk about the just the S in SOLID, Single Responsibility Principle, and what a right mess I can make of it.
I think Single Responsibility Principle attracts developers, even those who don’t know much else, if anything, about SOLID. It is the simplest of the principles to understand. I mean, anyone with any coding experience has built (or, if you won’t admit up to it, then, at least, experienced) the horrors of classes and functions 1000s of lines long.
It also appears, on the surface at least, the easiest to implement with little difficulty. At least this was the case for me.
It should be easy, and it feels easy, it makes sense and you can hit the ground running with it. But beware, it can be a subtle and deceptive beastie.
Now, in this series of posts, I guess I am just charting my own turbulent past with SRP, and happy to admit that my errors may not be indicative of the average developer – I may be a special case – however I have seen enough code bases to spot some fairly regular mistakes.
That said, however, please don’t think I’m trying to discourage the use of SRP. In fact, I encourage it. At worst, you will have a code base just as disorganised as you would have had otherwise, with the benefit that your team mates won’t mutter things under their breath about you, every time they have to fix something in your 12496 line long uber-class.
On the other hand, even if you only fall for some of the traps I’m going to outline, you’ll still end up in a better place. Either way, you will hopefully learn something from your endeavors. You may even prove me wrong, and do it right the first time – if so, congratulations, you bested me 🙂