Understanding the SOLID principles

These 5 principles are great advice discovered by Robert Martin also known as "Uncle Bob", the same we heard a podcast blog entrance ago. His acronym makes it easier for learning his principles, whenever we're developing object-oriented programs. The 5 principles are listed down below:

Single Responsibility Principle (SRP):

States that any class should have only one responsibility, although the author at some point says that there could be some classes that have 2 responsibilities. As the author continued with his explanation it confused me a little bit, because he contradicts himself. Maybe it could be clearer with the practice, as it's with all things in life. 

Open/Closed Principle (OPC):

States that a class or a function should be open for extension but closed for modification. It attempts to counter the tendency for object-oriented code to become easy to be broken.  When adding new behaviour you need to leave alone the base classes instead you should create a new class, to help avoid the problem.  

Liskov Substitution Principle (LSP):

Basically what Liskov substitution states it's to avoid inheritance, as we saw above. Actually, for my understanding, it's helpful advice, and we should use more often composition.

Interface Segregation Principle (ISP)

For me this principle it's new, it states that instead of having a huge interface that has many different methods, we should create small interfaces. And it makes sense, it's easier for a coder to refactor small pieces of code rather than huge parts of code. 

Dependency Inversion Principle (DIP):

Last but not least DIP states that we should code base on abstractions rather than on concrete objects, in all my programming languages it's the first advice that all the professors give, and for me, it has worked perfectly.



Comentarios

Entradas más populares de este blog

Ethical Reflection on Ready Player One

Software Craftsmanship

Hidden Figures