Nothing in this post is original. It’s just my reduction of the principles of class design from Uncle Bob in his Principles of OOD. If you don’t want to read, listen to the Hanselminutes interview with Bob. I just want to record my thoughts on these items here for posterity.
SOLID is just another acronym but if you are writing code it’s one you ought to know about.
SRP – Single Responsibility Principle: “A class should have one, and only one, reason to change.”
OCP – Open Closed Principle: “You should be able to extend a class’s behavior without modifying it.”
LSP – Liskov Substitution Principle: “Derived classes must be substitutable for their base classes.”
ISP – Interface Segregation Principle: “Make fine grained interfaces that are client specific.”
DIP – Dependency Inversion Principle: “Depend on abstractions, not on concretions.”
These are not new ideas and I’ve not visited these lately nor can I claim to practice these principles in everything I do. In fact, I’m sure that I don’t, but I am convinced that the more I follow these principles, the better my code will be.
I’m going to spend the next few days reabsorbing these and reading the PDF docs on the www.objectmentor.com site. If you want to follow along with me, start at the top of this post and follow the links.