The Single Responsibility Principle (SRP) states that any class must have one, and only one, reason to change. If a class has more than one reason to change, it should be refactored.

The primary benefit the Single-Responsibility Principle gives you is high-cohesion, low-coupling code.

Cohesion refers to the degree with which elements of code belong together. This means that the level of cohesion between elements is higher if they are related, and lower if they are not. Having a class with many methods that do one job (or aspects of one job, depending on your definition) means that that class has high cohesion.

Coupling is the manner of independence between modules of a programming system. This means that high coupling means that modules are more dependent upon one another, and low coupling means they are less dependent.

Essentially, following SRP minimizes the possible times more than one class will have to change for a given requirement, and maximizes the possibility that changing one class will not impact any other classes. This results in high-cohesion and low-coupling code, an ideal situation when changes arise (as they inevitably do) because it minimizes the impact any changes have on the affected code and its related modules.

#solid principles #programming-c #csharp

The Single Responsibility Principle - SOLID in C#
1.40 GEEK