SOLID principles

T.Oumaima
2 min readDec 14, 2021

Why do we need SOLID principles? Well because Uncle Bob said so.

I mean because they make life easy when you need to refactor or maintain your application code in the future. They protect your application against code smell and keep it clean and tidy, etc... They are also very compatible with building an application in an incremental way.

After the success of L.O.V.E .  Frank Sinatra last single song S.O.L.I.D :D
After the success of his song L.O.V.E . Frank Sinatra Spells for us S.O.L.I.D !

S is for Single Responsibility principle:

Each class or building block of your application should be covering one single responsibility in your application. This would be very useful for unit testing your application or maining it in general.

O is for Open-Closed principle:

A class or a building block is open for extension but closed for modification. It means if you need to add a new functionality to your class don’t modify the existing functionalities in the class but try to extend the class with the new wanted functionality. In this way you avoid making any trouble for the other code that uses the class without you new functionality.

L is for Liskov Substitution principle:

In class inheritance, the child should be able to substitute the functionalities of the parent without modifying them. A is a child of B, means A can do the functionalities B exactly as B do them.

I is for Interface Segregation principle:

It is found to avoid a class to be forced to implement all the functions even if they don’t need them all. The principle reduce the boiler plate of the class by limiting the interface to only have the functions that are needed by a class.

D is for Dependency Inversion principle:

This principle comes to deal with the case when a high level (class or module) needs some functionalities that are in low level (class or module) then principle says that is then a good idea to create an abstraction from which they can both implement that functionality. The abstraction should not know about implementation details but details should depend on that abstraction. We ensure in that way that high level (module/classes) do not depend on low level (module/classes) and make sure that (modules/classes) are loosely coupled which is an important paradigm in OOP(object oriented progamming).

Conclusion:

Good news, we have spelt all the letters in SOLID. These principles are the fruit of many years of experiences in software engineering. Applying them will save a lot of time and effort that you spend in a project. But being too much SOLID can make your project breakable. That’s why it is very important to discuss with your teamates what are SOLID principles that make more sens for your project :). Remember, apply SOLID principles and make a room for flexibility.

--

--

T.Oumaima

My blog is a balance between my love for technology, poetry and books.