Clean Code! SOLID
I think the only thing that makes a developer senior is knowing how to code clean! We have 5 solid principles in coding in a way that is extensible with fewer changes and fewer side effects, and readable for other developers. I am going to explain them in a very simple way.
S-> Single Responsibility Principle.
This says that every single module should be responsible for only one thing. For example, we cannot have a class that is responsible for calculating and printing! Why? Because in the future, if you want to change that responsibility you know where is it in the code (readable) and it produces no side-effects (bugs)💧
O-> Open/Closed Principle.
The software should be open to extensions and close to modification. For Example, if you want to add new features, it is not needed to change a huge amount of codes. Why? Because you didn’t change the previous codes, you are sure that the software is working as before so you make the maintenance cost less.🔓
L-> Liskov Substitution Principle.
If S is a subType for T, then the object of T can be a substitution for S with exactly the same result. Why? Because in this way we can find the correct inheritance and if the Liskov is satisfied, we satisfied the open-closed principle too.🌀
I-> interface segregation principle.
This one is simple, just don’t waste the interface!! Or if you implement an interface for the class all the elements in the interface should be available for the class, or you have to segregate the interface. Why? This can help us in following the first principle which is the Single Responsibility Principle.🦦
D-> Dependency Inversion Principle
Dependencies should be only to abstractions, not concretion. Why? It provides a way to separate the creation of an object from its usage. By doing that, you can replace a dependency without changing any code and it also reduces the boilerplate code in your business logic🗝
Get Niloofar Arazkhani’s stories in your inbox
Join Medium for free to get updates from this writer.
That is all, remember that take the modules to single responsible, pay attention to Liskov Substitution when using inheritance because in this way you are paying attention to open closed principle too. Don’t waste interfaces and abstractions are good parents 😂
Originally published at https://niloodeveloper.hashnode.dev.





