The article of this week emphasizes again how to improve our code, to make it more efficient, ease maintenance and reuse it. Five principles are mentioned, which we should follow to improve our practices when developing code. These five principles were first identified by Robert "Uncle Bob" Martin, but the acronym SOLID (by the initials of each principle) was introduced later by Michael Feathers.
Each of these principles establish certain rules to follow, below they mention each of them with its brief explanation.
1. Single Responsability
Principle
It states that you must give only simple responsibilities to the classes, thus avoiding dependence between them. It also specifies that can be assigned to a class the responsibility of a group of classes, all to facilitate future modification of code without affecting the other classes.
2. Open/Closed Principle
It states that classes should be open for extension, but closed for modification. It is recommended to control the behavior of each of the classes through inheritance. The main objective is to avoid making modifications to classes, it is better to have an extension that controls everything and make the change directly on it.
3.
Liskov Substituiton Principle
This principle is similar to the previous, except that it focuses on maintaining a good relationship between classes and functions. Also recommended not to make changes in base classes.
4. Interface
Segregation Principle
It states that we should avoid writing large interfaces. To improve recommends creating collections that contain these interfaces discreetly and smaller, through dividing into groups depending on what interfaces do.
5. Dependency Inversion Principle
The last principle states specifically, avoid dependence. It recommended interfaces to carry out the relationship between the classes that we want to have relationship.
Each of these principles are aimed at improving practices writing code and ease of maintenance, modification and reuse it.