Single Responsibility Principle – A class should be developed such a way that it should not change for more than one reason in other words a class should have one and only one reason to change.
SRP (Single Responsibility Principle) focuses on one thing one responsibility. All the methods of a class which follows the SRP principle should relate to a single purpose. It is very easy to identify the violations of SRP in a class, that class is too big and complicated with doing too many things which are unrelated.
The easiest way to fix this is to split the class based on the functionality.
- Making all member variables private so that other parts of the code access those using getter and setter methods.
- Second point is to avoid typecasting the classes at runtime.
Advantage of following OCP is developer can easily change the code by without breaking the existing behavior.
In simple terms we can say Liskov Substitution Principle is a contract between the base and derived classes, if base is satisfied with the contract so that derived class must satisfy with the contact.
Interface Segregation Principle – ISP tells about keeping the interfaces minimal and cohesive which can be maintainable.
Problem with huge interfaces is you are forcing the classes to implement all the methods which was a burden to the developer. To fix the ISP violations break down the interfaces by applying Single Responsibility Principle which makes fine grained interfaces.