22-JAN-2023
2 min
Photo by Joanna Kosinska on Unsplash
SOLID is a mnemonic acronym that stands for five design principles of object-oriented programming. These principles were first introduced by Robert Cecil Martin (Uncle Bob) in his paper "Design principles and design patterns". According to Robert Cecil Martin, these principles are not rules, laws or perfect truths. They are commonsense solutions to common problems.
The Single Responsibility Principle (SRP) states that each software module should have one and only one reason to change. In other words, a class or a module should have only one responsibility. The main idea of this principle is to increase the cohesion between things that change for the same reasons, and we want to decrease the coupling between those things that change for different reasons.
The Open Closed Principle states that a module should be open for extension but closed for modification. In other words, a class or a module should be extendable with requiring any modification. This principle encourages the use of polymorphism and interfaces, allowing us to add new functionality without modifying the existing code.
The Liskov Substitution Principle states that Subclasses should be substitutable for their base class. This principle encourages the use of inheritance and polymorphism to maintain the integrity of the program.
The Interface Segregation Principle states that many client specific interfaces are better than one general purpose interface. In other words, the interface should only contain methods that are required by the client that is implementing the interface. This principle encourages the use of many small and specific interfaces.
The Dependency Inversion Principle states that Depend upon Abstractions, Do not depend upon concretions. In other words, every dependency should target an interface or an abstract class and should not target a concrete class.