SOLID Design Principles Explained – C#

To Design a application  we need to follow some set of principle. SOLID principle is main in that.

SOLID is an acronym:

  1. Single Responsibility Principle (SRP)
  2. Open Closed Principle (OCP)
  3. Liskov Substitution Principle (LSP)
  4. Interface Segregation Principle (ISP)
  5. Dependency Inversion Principle (DIP)

 

Single Responsibility Principle (SRP)

“A class should have only one reason to change”

SRP states that a class should not be loaded with multiple responsibilities and  single responsibility should not be spread across multiple classes or mixed with other responsibilities.

The reason is that more changes requested in the future, the more changes the class need to apply.

Open Closed Principle (OCP)

“Classes should be open for extension, but closed for modification.”

OCP states that the class should be easily extended but there is no need to change its core implementations.The application or software should be flexible to change.New features should be implemented using the new code, but not by changing existing code

Lizkov Substitution Principle (OCP)

“LSP states that the child class should be perfectly substitutable for their parent class.”

If program or module is using base class then derived class should be able to extend their base class without changing their original implementation.

Interface Segregation Principle (ISP)

“ISP states that No client should be forced to implement methods which it does not use”

We need to break down classes, a class with lot  of implementation and used as a base class is not a good design. For that reason we can create separate interfaces for each operation or requirement rather than having a single class to do the same work.

Dependency Inversion Principle (DIP)

DIP states mainly two methodology they are

“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.”

It states that we must use abstract class or interfaces for reducing tight coupling among the software components.

 

Leave a Reply