S (Single Responsibility Principle):
A Class should have only one responsibility. Ex: User class should have functions only related to users.
O (Open/Closed Principle):
Open for extension but closed for modification. Means create interface and then extend it to new and old classes but don't change the old class.
L (Liskov Substitution Principle):
If class B is a subtype of class A then we should be able to replace the object of A with B without breaking the behaviour. Means subclass should extend the capabilities of parent class not narrow it down (If base class have 3 capabilities/functions then subclass should have at least 3 capabilities/functions).
I (Interface Segmented Principle):
Interface should have only necessary functions for subclasses.
D (Dependency Inversion Principle):
Class should depend on interfaces rather than concrete classes. Means always create an object of the interface.
Top comments (0)