Build scalable systems that accomodating change and are inherently testable using SOLID OO design principles
What are the SOLID principles of software design?
The SOLID OO design principles are a set of guidleines for building software that is modular, maintanable & testable. They consist of:
- Single Responsibility Principle
- Open Closed Principle
- Liskov Substitution Principle
- Interface Segregation Principle
- Dependency Inversion Principle
Single Responsibility Principle
Every component should have one responsibilty. Another way to look at it is that each object should have only one reason to change. This results in code that is much easier to understand and test.
Open Closed Principle
The goal here is to build code that is open to extension and closed to modification. In the future if a new requirement is created we shoud be able to introduce the functionality by changing as little existing code as possible.
Liskov Substitution Principle
We should code to abstract contracts and at anytime be able to replace objects that subclass or implement these contracts for one another transparently to clients. Some developers may recognize this principle by it’s old school name ‘polymorphism’
Interface Segregation Principle
The idea here is to create abstract contracts that are focused on a particular set of functionality and to not declare unneccesary functionality. In outher words prefer many smaller interfaces to large uber ones
Dependency Inversion Principle
This principle builds on the notion of coding to abstract interfaces instead of concrete classes and turns it on it’s head by introducing abstractions that sit between high and low level components in our systems.
Conclusion
Adopting the SOLID principles help to enure software of high quality that is adaptable and flexible.