One of the most important concepts that I was asked for in my last job interview was “what is SOLID?, are you familiar with the SOLID principles?”  .

And this is important because SOLID stands for five principles for object designing, you known, before start coding you should design your solution.. right? ….. right? ok.

So what SOLID stands for?

S : Single responsibility – Your class must have one single responsibility, if you are creating a class for “sending a mail” that is the only task that should do, not validating, not connecting, not applying a template, only to send the mail, the other tasks should be done by other classes.

O : Open/Close – When you are designing an application that probably will be need extended in the future, you should be sure that your design is open to extend the functionality but closed to modify it. If you need to modify a core functionality in order to update your application then your design is probably incorrect.

L : Liskov Substitution – After te “O” principle is when SOLID starts to be interesting. Liskov Substitution states that  subclasses  must be suitable for the parent classes,  in other words, if you are inheriting a parent class and you HAVE to override a method with a “return null” or throwing a “NotImplementedException”or you completely changed the functionality of the parent method then you are violating the Substitution Liskov .

I : Interface segregation- This is very similar to Single responsibility but applied to interfaces, interfaces are for the clients not for the application. So you want to segregate your interfaces in particular tasks rather than create a giant interface that makes everything and your client has to create dummy implementations.

D: Dependency Injection – This principle is the most important, DI allows to build loose coupled code, because other class doesn’t know the details of how create an instance another method to start working with it. Instead calling a constructor  a DI manager will inject the instance to the class through the constructor or a setter method.