Understanding the SOLID Principles
The article
tells us about the principles of SOLID, which are used to avoid dependencies,
because we all know that if more thing depends on other things, something is
going to go wrong, and we do not want that, so the five principles are:
-Single
Responsibility
-Open/Close
-Liskov
Substitution
-Interface
Segregation
-Dependecy
Inversion
The Single Responsibility,
as the name state, say that the class or method should have only one job, that also
does not depend of another, it could happen but is not the most recommendable
thing to do. One problem that it has is defining which is the responsibility of
the class or method, how much can you group in the “responsibility”.
The
Open/closed says that the class should not be open for modification or in a
better sense, closed. This means that if you want to add some new behavior, you
should create a new class with this new behavior that you want.
The Liskov substation
takes from the open/closed principle in a way that you should be able to
interchange the functions that are inherit in the child classes. There is no
much to say about this one really.
Interface
Segregation is also a really simple principle, says that you do not want to
have a big interface you could have various but more simpler interfaces to be
comprehensible.
The Dependency
Inversion is another principle that I really straight forward in its
descriptions, it says that instead of making a code that refers to classes, you
need to make that it refers to interfaces or in its defect to abstract classes.
For
conclusion, I do not really get many of this principles, although I see it
makes the code much more legible to say, it also makes the code much bigger in
a grand scale I say, but maybe is my student mind that is doing this talking
and once I get to work in start to write and see code in the real field, I can
think back and see how this principles are so in the right.
Comentarios
Publicar un comentario