SOLID Principles
Overview
The SOLID principles are probably the best known set of software engineering principles. They were first described by Robert J. Martin in 2000. The SOLID acronym has made them some of the easiest to remember and so the most popular.
The SOLID principles are:
- Single Responsibility Principle
- Open/Closed Principle
- Liskov Substitution Principle
- Interface Segregation Principle
- Dependency Inversion Principle
How important these principles really are depends a lot on who you talk to. In general, you should be following these principles as you work, and in places where you violate them, you should have a good reason for doing so.
None of these are absolutes, and should be applied thoughtfully.
📄️ Single Responsibility Principle
Each class should have only one reason to change.
📄️ Open/Closed Principle
Classes should be open for extension but closed for modification.
📄️ Liskov Substitution Principle
Derived classes must be substitutable for their base classes.
📄️ Interface Segregation Principle
The Interface Segregation Principle states that a class should not be forced to implement interfaces it does not use.
📄️ Dependency Inversion Principle
High-level modules should not depend on low-level modules. Both should depend on abstractions.