What is solid principal in C#

S stands for SRP (Single responsibility principle)
A class should perform only task related to itsef not others.
e.g we have a employee class we have add,update,delete and fetchemployee method and on adding each employee we send a welcome mail.So we should not implement mail method in employee class.we should create a seperate class for mailing

O stands for OCP (Open closed principle)
A class should desighned in such a way if there is any change in a already develoved class should be closed for modification but open for extension.This is because if you change in a existing,well tested,fine running method, you will have to re-test all cases which was not needed

L stands for LSP (Liskov substitution principle)
This principal says parent should easily replace the child object. the derived classes should be perfectly substitutable for their base classes. If class D,E is derived from A then D or E should be substitutable for A.
for example We can achive LSP in a abstract method of abstract class by assighning child instance in parent object as below
A obj= new E():
A obj= new D():

I stands for ISP ( Interface segregation principle)
ISP says If we are inheriting any interface Clients should not be forced to implement interfaces they don’t use. Instead of one huge interface, many small interfaces are preferred based on groups of methods, each one serving one sub module.“

D stands for DIP ( Dependency inversion principle)
High-level modules should not depend on low-level modules. Both should depend on abstractions. Abstractions should not depend on details. Details should depend on abstractions.”

e.g DI design pattern

Leave a comment