2-4: Understanding the SOLID Principles

The first thing that came to my mind when I read the title of the lecture was, what does SOLID stands for? So, first let me contextualize what is SOLID and then explain the meaning of all the letters in this acronym.

As I said before, SOLID is an acronym that stands for five principles of object-oriented programming and design. The objective of these principles is the avoidance of dependencies, because the more things you depend on, the greater the chance something will go definitively wrong; these 5 principles are the following ones:
  1. S => Single Responsibility Principle (SRP): States that a class should have exactly one responsibility. This means, that it should have exactly one reason (or one class of reasons) that cause it to be changed; nevertheless, many programmers have the superstition about the systems they maintain things like "Don't touch this module" or the difficult task of selecting that single responsibility.
  2. O => Open/Close Principle (OCP): States that a class (or function) should have the following behavior; should be open for extension but closed for modification. This principle attempts to counter the tendency for OO code to become fragile or easily broken. In a nutshell, OCP means that when adding new behavior, you should leave base classes alone and instead create new, inheriting classes, adding behavior to these instead of the base class.
  3. L => Liskov Substitution Principle (LSP): The LSP is similar to the Open/Closed Principle. Both, OCP and LCP imply that you should avoid modifying the behavior of a base class, but the LSP forbids modification of that behavior through the mechanism of inheritance.
  4. I => Interface Segregation Principle (ISP): It says to avoid writing monstrous interfaces that burden classes responsibilities they don't need or want. Instead, create a collection of smaller, discrete interfaces, partitioning interface members according to what they concern.
  5. D => Dependency Inversion Principle (DIP): Says to depend upon abstractions, not upon concretions. Instead of writing code that refers to actual classes, you should instead write code that refers to interfaces or perhaps abstract classes.

Comentarios

Entradas populares de este blog

Summary Second Period

2-3: Microservices