Skip to content
jethrokyq edited this page Mar 18, 2021 · 1 revision

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.

Single Responsibility Principle:

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.

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 bugs in the application.

Liskov Substitution

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.

Interface Segregation

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.

Dependency Inversion

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.