SOLID Principles - Explanation
SOLID Principles -Explanation
1. Introduction
In this blog we'll be discuss about the SOLID principles in Object Orient Design. Here we can easily identify these principles along with the codes that I provided. This SOLID principle design concept was first conceptualize by the Robert C. Martin in 2000,Design Principles and Design Patterns.
Later, this concept was more build up and polish by Michel and Feathers. So, how this SOLID principles will help us to do a better coding? According to Michel and Feathers these principle will encourage to create our software more reliable, maintainable, understandable and flexible. Even though our codes getting more grow in size and lengthy these principle will help to keep those more simple and more reusable.
SOLID principles,
- Single Responsibilities
- Open/Close
- Liskov Substitution
- Interface Segregation
- Dependency Inversion
1. Single Responsibilities
This principle mainly state that a class should only have one responsibility, Further it should have only one reason to change.
Benefits of Single Responsibility principle,
- Testing - Class with single responsibility will have few test cases
- Organization - well organized small classes are easy to search than complex and massive classes.
- Lower coupling - few dependencies are there in a single class with less functionality
2. Open/ Close
This principle simply means that this is object or entities should be open for extensions but close for modification. mainly, we stop modifying the existing code and causing potential new bugs.
3. LisKov substitution
This principle is more complex to identify and understand, when we compare it with other rest principles. This principles means that Every subclass/derived class should be able to substitute their parent/base class.
According to this concept when we extend a class it should perform basic functionalities of the base class. This simply mean that, if class B is a subtype of class A, so we should be able to replace A with B without disrupting the behavior of our program.
Further, Child class should not have any unimplemented methods and child class should not give different meaning to the methods exist in the base class after overriding them.
4. Interface Segregation
In SOLID principles 'I is stands for this Interface Segregation.it simply mean that "Client should not be forced to implement methods they do not use" further this means that larger interfaces should be split or divided in to smaller ones. by doing so the implement classes should concerned about the method that are really interest about them.
5.Dependency Inversion
"Higher level should not depend on lower level modules, but they should depends on abstractions"
posted By Dilshan K.G.T
Comments
Post a Comment