SOLID Principles 🗿
The SOLID principles are design principles that help create maintainable object-oriented software. SOLID stands for:
Principle | Description | Example |
---|---|---|
Single Responsibility | A class/module should have only one reason to change. It should have a single responsibility. | A class that parses and validates input. Split into two classes. |
Open Closed | Software entities should be open for extension but closed for modification. | A payment processor that supports new payment methods via new classes rather than change. |
Liskov Substitution | Objects should be replaceable by their subtypes without affecting program behavior. | A rectangle class that can be substituted for a square class without issue. |
Interface Segregation | Client specific interfaces are better than one general purpose interface. | Separate mouse/keyboard interfaces instead of one input device interface. |
Dependency Inversion | Depend on abstractions rather than concretions. | Depend on a persistence interface rather than a MySQL class. |
Benefits
- Improved maintainability
- Change accommodation
- Testability
- Loose coupling
SOLID guides developers to create software with components that are cohesive, reusable and maintainable. Applying SOLID can take practice but pays off in long term code quality.
Last updated on