Who should read it: It is for you if you are looking for a quick overview of this topic for a project, an interview, or in general. As I learn more, I will update this article.
What are SOLID Design Principles:
SOLID Design Principles stand for:
- Single Responsibility Principle
- Open/Closed Principle
- Liskov Substitution Principle
- Interface Segregation Principle
- Dependency Inversion
Single-responsibility Principle:
It states that a class should have one and only one reason to change, meaning that a class should have only one job. For example, if a class has a function to calculate the area of the shape ( like circle, square, or a circle), it should focus only on it. If we want to output the result into a JSON or a TEXT format, it is advisable to use another class that forms the output in the desired format. Do just one thing in a class.
Open-Closed Principle:
It states that Objects or entities should be open for extension but closed for modification.
Liskov Substitution Principle:
It states that 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. Means, every subclass or derived class should be substitutable for their parent or base class.
Interface Segregation Principle:
It states 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.
Dependency Inversion Principle:
It states that the entities must depend on abstractions, not on concretions. It states that the high-level module must not depend on the low-level module, but they should depend on abstractions. This principle allows decoupling.