Understanding the SOLID Principles

S.O.L.I.D is an acronym for the first five object-oriented design principles designed by Bob Martin, popularly known as Uncle Bob.

Uncle Bob wanted these principles so that combined together would make it easy for a programmer to develop software that is easily maintainable and scalable. They also wanted to make it easier for developers to avoid and detect code smells, refactor code more efficiently. Basically, these principles have been deeply used in current trending practices like agile development.

SOLID means this:

-       Single responsibility principle
-       Open/closed principle
-       Liskov substitution principle
-       Interface segregation principle
-       Dependency Inversion Principle

The first principle states that a class should have one and only one reason to change, meaning that a class should have only one job.

The second, that objects or entities should be open for extension, but closed for modification. This means in less complicated words that a class should be easily extendable without modifying the class itself.

The third principle is: Let q(x) be a property provable about objects of x of type T. Then q(y) should be provable for objects y of type S where S is a subtype of T. Again this means that every subclass/derived class should be substitutable for their base/parent class.

The fourth is that a client should never be forced to implement an interface that it doesn't use or clients shouldn't be forced to depend on methods they do not use.

The last one states that entities must depend on abstractions and not on concretions. A bit more technical, the high-level module must not depend on the low-level module, but they should depend on abstractions.

Having these principles in mind while designing software will pay off in the near future when requirements start changing on the software or there is a need to extend functionalities.

Comentarios

Entradas populares