Understanding the SOLID Principles

In this blog, I will discuss a section from the book "Ace the Programming Interview: 160 Questions and Answers for Success" by Edward Guinness published by Wiley in 2013. The section I will discuss in this blog is called "Understanding the SOLID Principles".

So first of all what does SOLID stand for? It stands for:

  • Single Responsibility Principle
  • Open/Closed Principle
  • Liskov Substitution Principle
  • Interface Segregation Principle
  • Dependency Inversion Principle
Lets try to briefly understand what each of this mean.

  • Single Responsibility Principle: Like the article says, a class should only have one responsibility and there never should be more than one reason for the class to change. One good way of applying this principle is asking yourself whether the logic you are coding into your class should live there or not.

  • Open/Closed Principle: This principle states that software entities should be open for extension but closed for modification. One way of doing this is to make all member variables private.

  • Liskov Substitution Principle: LSP states that objects in a program should be replaceable with instances of their subtypes without altering the correctness of the program. The objective of this  is to keep the good relations between classes and functions.

  • Interface Segregation Principle: It states that programmers should building ugly or monstrous interfaces that flood classes with responsibilities they don’t really need. You should instead partition and create small interfaces that distribute between responsibilities.

  • Dependency Inversion Principle: It states that abstractions should not depend upon details and the details should not depend upon abstractions. Basically, try to use the same level of abstractions so one type of thing is not depending on its same type.

I heard of this principles before but readingthis portion of the book has made me understand their importance when programming decent code. Systems usually have a lot of dependencies and it's vital for the inner workings of the system to be efficiently coupled so their maintenance or extension in the future can be done smoothly.

Comentarios

Entradas populares de este blog

Is Design Dead?

Software Craftsmanship