Understanding the solid principles
This article talks about the SOLID
principles which in fact as you known is
an acronym that stands for five principles of object-oriented
programming and design. Those principles allow us to avoid dependencies. So
that means that the more things you depend on the greater the chance of something
will go wrong. The principles are: Single Responsibility Principle, Open/Closed
Principle, Liskov Substitution Principle, Interface Segregation Principle and
Dependency Inversion Principle.
I will talk about
them quickly and explain why are they so important in our life as programmers.
The single responsibility principle talks about that a class should have
exactly one responsibility. That means that we have to have classes with a specific
purpose and not mixed classes that if we erase something all the code went
wrong or different. The open/closed principle talks about that a class should
be open for extension but closed for modification. That means that we have to
counter the tendency for object-oriented code to become fragile or easily
broken.
The Liskov Substitution
Principle talks about that we have to keep that working relationship between
classes and functions. That means that Liskov forbids modification of that
behavior through the mechanisms of inheritance. This principle allows us
particularly to be free to substitute a child class in a function that expects
to deal with the base class.
The interface
segregation principle talks about that we have to avoid writing monstrous
interfaces that burden classes with responsibilities they do not need or want.
That means that we must create a collection of smaller, discrete interface,
partitioning interface members according to what they concern. And finally, the
dependency inversion principle talks about that instead of writing code that
refers to actual classes, we must instead write code that refers to interfaces
of perhaps abstract classes. I think that if we follow this SOLID principle our
codes will be better and easier to read, don’t you think so?
Comentarios
Publicar un comentario