SOLID
Although the SOLID principles are something that should be,
at least, common in object-oriented programs, we programmers tend to forget
about some of them and incur in practices that negatively affect our code. From
the beginning when we are taught OOP, we might not be aware of these principles
even if we tend to gravitate towards some of them depending on how we learn to OOP
program.
For a start, I think that when we learn to program in the
Object-Oriented Mode, we usually are taught to apply Single Responsibility
because it is easier to think about classes as a description of an object that has
a set of characteristics and one function. It might cost a little at the beginning
to effectively accomplish this, but when you gain some practice, for the sake of
clarity this is usually the go-to way.
The next most usual behavior I follow is the Interface Segregation
Principle. Since it is somewhat similar to the Single Responsibility, it is easier
to understand and then apply in the code. It does not come as simple as the first
one, but I think it is still easier to find than the other three principles.
On the other hand, Dependency Inversion I consider is
something that you are taught from the start and don’t really understand until you
have practice and have to deal with lots of weird dependencies in your code. It
takes practice to learn it, but I think it is a really useful principle if you
want to achieve low dependency and high compliance without shooting yourself in
a foot.
The other two principles I think are the ones we tend to
forget the most, and I consider that this happens either because we don’t want
to waste time learning how to optimize our code or we do not come to understand
them. Particularly with the Liskov Substitution principle, since it may seem
that contradicts a little the model of OOP.
Comentarios
Publicar un comentario