Image for post
Image for post

SOLID Principles Around You

Oleksii Trekhleb
Jun 20, 2017 · 2 min read

In this article I want to briefly go through SOLID principles (acronym that stands for five basic principles of object-oriented programming and design) supplying each of them with real-world visual examples to make those principles more understandable, readable and memorizable.

If you want to see code examples instead you may take a look at variety of tree data structure implementations in JavaScript like Binary Search Tree, AVL Tree, Red-Black Tree, Segment Tree or Fenwick Tree.

So let’s move on!

S — Single Responsibility Principle

[a.k.a SRP] A class should have only a single responsibility. Only one potential change in the software’s specification should be able to affect the specification of the class.

O — Open/Closed Principle

[a.k.a OCP] Software entities should be open for EXTENSION, but closed for MODIFICATION. Allow behavior to be extended without modifying the source-code.

Image for post
Image for post

L — Liskov Substitution Principle

[a.k.a. LSP] Objects in a program should be replaceable with instances of their subtypes without altering the correctness of that program.

Image for post
Image for post

I — Interface Segregation Principle

[a.k.a. ISP] Many client-specific interfaces are better than one general-purpose interface. No client should be forced to depend on methods it does not use.

Image for post
Image for post

D — Dependency Inversion Principle

[a.k.a. DIP] One should depend upon abstractions, not concretions.

  • High-level modules should not depend on low-level modules. Both should depend on abstractions.
  • Abstractions should not depend on details. Details should depend on abstractions.
Image for post
Image for post

I hope these illustration have been useful for you :) Thank you for your attention!

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store