What are SOLID Principles? Explained with OOP Concepts.
SOLID Principles |
Software developers implement codes to meet the users' requirements and satisfy the clients. Some principles have to follow by software developers to enhance their code writing skills.
The SOLID principles have considerable responsibility to guide the software developers, to make the software design by improving the code quality.
An American software engineer named Robert C.Martin created this principle.
Why do we need SOLID principles?
Advantages of using SOLID Principles.
- Make the code more understandable and readable.
- Make the code snippet as simple as possible by reducing the complexity.
- Make the lines of codes flexible. Therefore the code snippets are updatable or modifiable when required.
- To maintain the software codes easily.
- To reduce the dependencies.
- To make the code testable.
- To implement the code.
Solid principles have five(5) principles. The name is created by considering the first five letters from each principle.
5 SOLID Principles
Let us have a look at each of the principles separately.
1. S - Single Responsibility Principle
This principle explains that a class has to contain one responsibility.
Example:
Let us assume a stock management project is implemented for a textile shop. There are many different teams, and they have to change one particular class to implement some functionalities due to distinct purposes. So the modified classes will become complex and incompatible due to several changes.
2. O - Open Closed Principle
This principle explains that a class can handle extensions without being modified. So if we need to add some functionalities to previous classes, it is better to create another abstract class or interface and include the functionalities. It helps to save implementing time.
Example:
Let us assume there is a student management system for a university. The students can be undergraduate students or post-graduate students. There can be some attributes that are common for both classes. Then the undergraduate students and post-graduate students can be considered as child classes and the person as the parent class to store the common attributes. So both the child classes inherit the parent class.
3. L - Liskov Substitution Principle.
This principle explains that the parent class has to be substitutable with the child class.
4. I - Interface Segregation Principle.
This principle explains the separation of the interfaces.
Due to the separation of the interfaces, a particular client will be given access to relevant functionalities. That particular client will not access the interfaces that are irrelevant.
5. D - Dependency Inversion Principle.
This principle explains that the classes have to depend on interfaces or abstract classes. It should avoid the dependability of concrete classes or functions. This principle helps to enhance the reusability of the code.
Conclusion
Thanks for reading my blog by spending your time. I hope this blog will help you to gain knowledge about solid principles.
If you like this blog, share it and show some love.
You can read more of my future blogs by following me through my social media.
LinkedIn Twitter Dev Community
References
- https://medium.com/backticks-tildes/the-s-o-l-i-d-principles-in-pictures-b34ce2f1e898
- https://www.digitalocean.com/community/conceptual_articles/s-o-l-i-d-the-first-five-principles-of-object-oriented-design
- https://www.bmc.com/blogs/solid-design-principles/#:~:text=SOLID%20is%20an%20acronym%20that,some%20important%20benefits%20for%20developers.
Comments
Post a Comment