As they say, “A picture is worth a thousand words”. Just came across some motivational posters on Uncle Bob’s SOLID Principles on software design. If you are a software developer who likes to keep an eye on what’s going on in the object -oriented (OO) development fraternity, chances are that you would have come across the famous clash of OO titans (Joel vs UncleBob). Interesting perspectives, but that’s a different story altogether and will get into that some other time.
Uncle Bob’s SOLID principles are a collection of five OO design principles. These are:
1. Single Responsibility Principle (SRP)
2. Open Closed Principle (OCP)
3. Liskov Substitution Principle (LSP)
4. Interface Segregation Principle (ISP)
5. Dependency Inversion Principle (DIP)
THERE SHOULD NEVER BE MORE THAN ONE REASON FOR A CLASS TO CHANGE.
SOFTWARE ENTITIES (CLASSES, MODULES, FUNCTIONS, ETC.) SHOULD BE OPEN FOR EXTENSION BUT CLOSED FOR MODIFICATION.
FUNCTIONS THAT USE REFERENCES TO BASE CLASSES MUST BE ABLE TO USE OBJECTS OF DERIVED CLASSES WITHOUT KNOWING IT.
CLIENTS SHOULD NOT BE FORCED TO DEPEND UPON INTERFACES THAT THEY DO NOT USE.
HIGH LEVEL MODULES SHOULD NOT DEPEND UPON LOW LEVEL MODULES. BOTH SHOULD DEPEND UPON ABSTRACTIONS.
ABSTRACTION SHOULD NOT DEPEND UPON DETAILS. DETAILS SHOULD DEPEND UPON ABSTRACTION.
Irrespective of whether you are on Uncle Bob’s side or Joel’s side, these principles to me are great pointers to a good software design. Of course, like any other engineering principles, these should not be treated as commandments. Rather the requirements of the project should dictate the degree of relevance of these principles in their case. That is where Coding becomes a Craft and not mere a discipline of science.
With that said, having the mind laden with these principles will definitely put ones thinking in the right direction. In the direction in which the fundamental requirement of all good software design can be achieved – “Loose Coupling”.