SOLID Principles Analogy + Swift

Shrawan K Sharma
5 min readSep 7, 2020

--

In object-oriented computer programming, SOLID is a mnemonic acronym for five design principles intended to make software designs more understandable, flexible, and maintainable.

How do you explain in Laymen’s terms that I am following SOLID Principles:-

MEASH Principles to keep your Amazing Health :-

i)Meditate
ii)Exercise
iii)Affirmations
iv)Sleep
v)Healthy food

Similarly, Developer follow SOLID Principles to write understandable, flexible, and maintainable code

SOLID stands for

  • S: Single responsibility principle
  • O: Open-closed principle
  • L: Liskov substitution principle
  • I: Interface segregation principle
  • D: Dependency inversion principle

Let’s discuss each acronym in layman’s terms

S: Single responsibility principle :- A class should have only a single responsibility (i.e. changes to only one part of the software’s specification should be able to affect the specification of the class).

You get a call from a Recruiter and they were hiring for frontend developer. You get a bunch of requirements.

  • ReactJS/Angular
  • HTML/CSS
  • Node/Python
  • Mongodb/mysql
  • Microservices
  • Jenkin
  • Docker
  • Java/Python
  • System Administration

You might be wondering this is not a single person job. This is the whole IT department in the software role. If you get selected for this position then you have to take multiple responsibilities at same time.

You took the offer with a condition that instead of working on multiple tasks at a time I will perform work by decoupling my task, so that your’s responsibility will be to see final output.

O: Open-closed principle :- software entities should be open for extension, but closed for modification.

You get a call from a Director after joining and asked to design a website.

You were happy to accept designing website tasks as you were open to extend new area and current routine was not affected by it(closed for modification).

L: Liskov substitution principle :- Objects in a program should be replaceable with instances of their subtypes without altering the correctness of that program.

You bought a Mac laptop along with a desk to place a laptop. The desk was having software built by Apple which only allows a 23-inch laptop.

— — — — —

‘’Cost of Apple Desk 3000$’’

— — — — — -

After some days you planned to buy a Windows laptop 40-inch to play Games and you replaced mac laptop with Windows ones.

Mac’s desk software was not compatible with the window’s laptop. Due to which desk software broke/corrupted your new brand laptop.

So you visited to a Software developer who knew “SOLID Principles”.

He updated the software. Now you can place any laptop on the desk.

I: Interface segregation principle :- many client-specific interfaces are better than one general-purpose interface.

There was a king who was lacking knowledge of solid principle. A common template is given to each family members in the Kingdom for daily tasks and they have to follow all the tasks strictly. You have to invest some time even if you cannot do it.
After 1 year, King was getting feedback about the rules that he implemented. He saw a lot of children are wasting time while they were washing clothes.

So King visited to a Software developer who knew “SOLID Principles”.

He hired a Software developer to solve that. He suggested the “Interface segregation principle”- which tells to break your single rules to small chunk and assign based on the capability.

Now a small child can watch the movie in spare time instead of following bogus rule.😊 😊 😊

D: Dependency inversion principle :- High level modules should not depend on low level modules both should depend on Abstractions.

You bought hypothetical new technology software that helps you to bring water to the desk from the freezer.

You were enjoying cool water from freezer. It was working well…

One day you thought let’s drink water from a tap. Company has built that software that was hard to modify by you, you need to call software developer to make changes….

Software developer arrived and added new logic so that tap water can be available if there is no refrigerator water.

After someday both the water sources were empty. You planned to drink from rain harvesting water which was last options.

You visit to a Software developer who knew “SOLID Principles”.

You asked him to make robust software that only takes the type of water that I want will deliver automatically. Make some rules which I will follow to get the result.

Hope this article is useful to understand SOLID principle

Please give your feedback on it, comment, like and share 😊 😊 😊

--

--

Shrawan K Sharma

iOS App Developer - Frontend(ReactJS) - Building innovative products - MNNIT