Tag Archives: Writing C# Code Using SOLID Principles

SOLID Principles

SOLID Principles Solid principles are used to design Software architecture.
SOLID Principles is an acronym Where
S – Single Responsibility Principle (SRP)
O – Open Closed Principle (OCP)
L – Liskov Substitution Principle (LSP)
I – Interface Segregation Principle (ISP)
D – Dependency Inversion Principle (DIP)
SRP It states that “Members of a class/structure should have same purpose to do”. Means if a class name is “User” then all the members of this class should be related to user.
OCP It States that “Existing classes/structure should be open for extension but closed for modification”. Means if we modify the existing classes then it will affect the users who are already using its functionality.
LSP It states that “A derived class should represent its base class.” Means we should be able to use derived class as a substitute to its parent class without changing its behavior.
ISP It states that “A client should not be forced to implement the interface methods in which he is not interested or they are not useful for him.” Means an Interface can have such methods which are not useful for some clients. In that case we should divide that Interface into small parts.
DIP It states that “High level modules should not depend on low level modules. Instead both should depend on abstractions. And Abstraction should not depend on details Instead details should depend on abstractions.”