Why Need To Use SOLID Principles in Programming?

SOLID Principles are coding standard that all developers / programmers must have follow as good understanding rules / regulations to develop software properly.

SOLID is an acronym that stands for five key design principles:

S – stands for Single-Responsibility Principle
O – stands for Open-Closed Principle
L – stands for Liskov Substitution Principle
I – stands for Interface Segregation Principle
D – stands for Dependency Inversion Principle

Single Responsibility Principle [SRP] :: very class should have a single responsibility or single job or single purpose and only one reason to change, meaning that a class should have only one job.

For Example Single Responsibility Principle:: While developing software, The task is divided into different members doing different things as

  • Front-end designers do design
  • Tester does testing
  • Backend developer takes care of backend development
  • Mobile App developer takes care of mobiles app development

Finally, we can say that everyone has a single job or responsibility.

Liskov’s Substitution Principle:: “Derived or child or sub classes must be substitutable for their base or parent classes“. This principle ensures that any class that is the child of a parent class should be usable in place of its parent without any unexpected behavior.

For Example Liskov’s Substitution Principle:: One of the classic examples of this principle is a rectangle having four sides. A rectangle’s height can be any value and width can be any value. A square is a rectangle with equal width and height. So we can say that we can extend the properties of the rectangle class into square class.

Interface Segregation Principle [ISP]:: A system / 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.

For Example Interface Segregation Principle:: Suppose if you enter a restaurant and you are pure vegetarian. The waiter in that restaurant gave you the menu card which includes vegetarian items, non-vegetarian items, drinks, and sweets. In this case, as a customer, you should have a menu card which includes only vegetarian items, not everything which you don’t eat in your food. Here the menu should be different for different types of customers. The common or general menu card for everyone can be divided into multiple cards instead of just one. Using this principle helps in reducing the side effects and frequency of required changes..

SOLID principle was introduced by Robert C. Martin, also known as Uncle Bob and it is a coding standard in programming.

Leave a Reply

Your email address will not be published. Required fields are marked *