On today’s blog we are
going to talk about the SOLID principles, which were discovered by Robert
Martin, the famous Uncle Bob from the podcast of the previous entry. This principles
are recommended to be used whenever someone wants to create an object oriented
program. There are 5 principles where the acronym SOLID comes from which are
the following
- Single Responsibility Principle (SRP) -> it says that any class should only have one responsibility. Yet, the author ends up saying that there might be some classes that have two responsibilities (the invoicing class that has some logging routines). In the end, I didn’t understand this principle well because I found the explanation confusing (as the author said, practice is much more difficult than theory).
- Open/Closed Principle (OPC) -> open extension but closed modification Although the author says that if you change a parent class method it might kill another part of the code, I think that this would only reflect your lack of knowledge of your own code, and we should have the capacity of modifying our own code.
- Liskov Substitution Principle (LSP) -> avoiding inheritance, as we have seen before, is actually a really useful advice. I think that we should try to use composition as much as we can.
- Interface Segregation Principle (ISP) -> I had never heard about this principle before, which describes that instead of having a huge interface that has many different methods, we should create a bunch of small interfaces. I find this principle pretty useful, because it is easier to refactor a small and well-organized code.
- Dependency Inversion Principle (DIP) -> this last principle says that we should code base on abstractions, rather than coding based on concrete objects. I think this is also a great advice. If we code thinking that our objects might changes, and that they should look like this, instead of being like this, it would be easier to modify them and to adapt the future.
Comments
Post a Comment