SOLID Principles of Software Engineering
SOLID is a popular set of design principles that are used in object-oriented software development. SOLID is an acronym that stands for five key design principles: single responsibility principle, open closed principle, Liskov substitution principle, interface segregation principle and dependency inversion principle.
* S -single Responsibility Principle
* O-open-Closed Principle
* L-Liskov Substitution Principle
* I-Interface Segregation Principle
* D- Dependency Inversion Principle
Single Responsibility Principle
Single-Responsibility principle (SRP) states:
A class should have one and only one reason to change, meaning that a class should have only one job.
This principle aims to separate behaviors so that if errors arise as a result of your change, it does not affect other unrelated behaviors.
Open-Closed Principle (OCP) states:
Objects or entities should be open for extension but closed for modification.
This principle aims to extend class behavior without changing the existing behavior of that class. This is to prevent errors wherever the class is used.
Liskov Substitution Principle
Liskov Substitution Principle states:
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.
This principle aims to enforce compliance so that the parent class or its child class can use it in the same way without any errors.
Interface Segregation Principle
Interface Segregation Principle states:
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.
This principle aims to divide an action group into smaller sets so that a class executes only the group of actions it needs.
Dependency Inversion Principle
Dependency Inversion Principle states:
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 aims to reduce the dependence of the upper class on the lower class by introducing an interface.
Advantages of SOLID Principles
- Ease of refactoring
You can get some basic knowledge about SOLID Principle.