Understanding the SOLID Principles
On this
entry we will discuss about the book section “Understanding the SOLID
Principles” by Edward Guiness from the book “Ace the Programming Interview: 160
Questions and Answers for Success” published by Wiley in 2013. This chapter
talks about principles for object-oriented programming and design. This will
make your code clearer, minimize dependencies and practical.
The first
is Single Responsibility Principle which mean that your class don’t have to be
mixed with many responsibilities, it is preferred to divide it in different
classes, one per task. The second, the Open/Closed Principle, states that a
class should be open for extension but closed for modification. According to the lecture you don’t have to
modify your class, you only need to create a new class that inherits from base
class and add the new function that you need.
Liskov
Substitution Principle said that you should be free to substitute a child class
in a function that expects to deal with the base class. The it is the principle
of Interface Segregation Principle which says that instead of creating a big
interface with many functions split it in a collection of smaller interfaces. So,
classes can then pick and choose what they implement rather than having to use
all or nothing.
The last
one is Dependency Inversion Principle a principle that offers you to write code
that refers to interfaces or perhaps abstract classes, instead of writing code
that refers to actual classes.
Provided
that, SOLID principles are guides that can be applied in the development of
software to eliminate code that is not correct, causing the source code to be
reprogrammed until it is readable and extensible. This serves to minimize the
dependency between the interfaces, that means that less dependent code, and
more code easy to understand, without having to compromise functionality.
Comentarios
Publicar un comentario