-
Notifications
You must be signed in to change notification settings - Fork 2
SOLID Principles
SOLID is an acronym for the 5 Design Principles outlined by Robert C. Martin, they are namely:
- Single Responsibility
- Open/Closed
- Liskov Substitution
- Interface Segregation
- Dependency Inversion
Following these design principles generally leads to more maintainable, understandable, and flexible software.
One class should only serve one purpose, this does not imply that each class should have only one method but they should all relate directly to the responsibility of the class. All the methods and properties should all work towards the same goal. When a class serves multiple purposes or responsibility then it should be made into a new class.
Classes should be open for extension, but closed for modification. In doing so, we stop ourselves from modifying existing code and causing potential new bugs in the application.
If class A is a subtype of class B, then we should be able to replace B with A without disrupting the behavior of our program.
The goal of this principle is to reduce the side effects of using larger interfaces by breaking application interfaces into smaller ones, doing so doing so, ensures that implementing classes only need to be concerned about the methods that are of interest to them. Adhering to this principle helps to avoid bloated interfaces with multiple responsibilities.
The principle of Dependency Inversion refers to the decoupling of software modules. Instead of high-level modules depending on low-level modules, both will depend on abstractions.