Skip to Content

SOLID Principles 🗿

The SOLID principles are design principles that help create maintainable object-oriented software. SOLID stands for:

PrincipleDescriptionExample
Single ResponsibilityA 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 ClosedSoftware 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 SubstitutionObjects should be replaceable by their subtypes without affecting program behavior.A rectangle class that can be substituted for a square class without issue.
Interface SegregationClient specific interfaces are better than one general purpose interface.Separate mouse/keyboard interfaces instead of one input device interface.
Dependency InversionDepend 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