All Articles

Let's be SOLID principles

This article was done using my notes from Samuel Oloruntoba: https://scotch.io/bar-talk/s-o-l-i-d-the-first-five-principles-of-object-oriented-design

The SOLID principle makes easy for a programmer to develop software that are easy to maintain and extend. SOLID stands for:

  1. S: Single-responsiblity principle
  2. O: Open-closed principle
  3. L: Liskov substitution principle (LSP)
  4. I: Interface segregation principle (ISP)
  5. D: Dependency Inversion Principle

Single-responsiblity principle

A class should have one and only one reason to change, meaning that a class should have only one job.

Open-closed principle

Objects or entities should be open for extension, but closed for modification. This simply means that a class should be easily extendable without modifying the class itself.

Liskov substitution principle

Every subclass/derived class should be substitutable for their base/parent class.

Interface segregation principle

A client should never be forced to implement an interface that it doesn’t use or clients shouldn’t be forced to depend on methods they do not use.

Dependency Inversion principle

Entities must depend on abstractions not on concretions. It states that the high level module must not depend on the low level module, but they should depend on abstractions.