- Single Responsibility
- Open/Closed
- Liskov Substitution
- Interface Segregation
- Dependency Inversion
Single Responsibility
A class should only have one responsibility. Furthermore, it should only have one reason to change.
- Testing – A class with one responsibility will have far fewer test cases.
- Lower coupling – Less functionality in a single class will have fewer dependencies.
- Organization – Smaller, well-organized classes are easier to search than monolithic ones.
Open for Extension, Closed for Modification
Classes should be open for extension but closed for modification. In doing so, we stop ourselves from modifying existing code and causing potential new bug
Liskov Substitution
if class A is a subtype of class B, we should be able to replace B with A without disrupting the behavior of our program.
Interface Segregation
The interface segregation principle (ISP) states that no code should be forced to depend on methods it does not use.
Dependency Inversion
High-level modules, which provide complex logic, should be easily reusable and unaffected by changes in low-level modules, which provide utility features. To achieve that, you need to introduce an abstraction that decouples the high-level and low-level modules from each other.
Reference :
https://stackify.com/dependency-inversion-principle/
Comments
Post a Comment