Member-only story

SOLID Principles – explained with code

Kong To
9 min readSep 2, 2019

SOLID are the 5 principles of software design. They were introduced by Robert C. Martin (Uncle Bob), in his 2000 paper Design Principles and Design Patterns. For developers, they are a foundation, on top of the 4 Object Oriented Programming (OOP) principles. As a remind, they are Polymorphism, Encapsulation, Inheritance and Abstraction.

SOLID stands for :

  • Single Responsibility Principle (SRP)
  • Open-Closed Principle Principle (OCP)
  • Liskov Substitution Principle (LSP)
  • Interface segregation Principle (ISP)
  • Dependency Inversion Principle (DIP)

These 5 principles are meant to be combined together. When applied to code design, so they will make software easier to maintain, extend and re-use, and the code easier to understand. Developers would produce cleaner code.

Reader’s guide

This article may be a bit too long to read, but in Software development, SOLID principles are to be used and applied together as a whole, it makes more sense to have them explained within the same post. To help the reader to better understand them, samples of code will be shown with applications of each of the 5 principles. These samples are part of a codebase as a whole, let’s call it legacy code…

--

--

Kong To
Kong To

Written by Kong To

Architect, Engineer, Developer, Code, Code Crafter... whatever but code quality matters

No responses yet