

Along with the other principles this permits looser coupling. As the classes perform only one duty, multiple classes will work together to achieve larger tasks.
SINGLE RESPONSIBILITY PRINCIPLE CODE
This reduces the need for changes so the code is less fragile. The creation of classes that are tightly focussed on a single purpose leads to code that is simpler to understand and maintain.Ī further benefit of having small, cohesive classes is that the chances of a class containing bugs is lowered. The number of classes present in a solution may increase accordingly so it is important to organise them well using namespaces and project folders. One key change is that the classes in your projects become smaller and cleaner. It may also be that multiple classes will require updates.Īpplication of the SRP can change your code considerably. It may be that when the one reason to change occurs, multiple members of the class may need modification. There may be many members as long as they relate to the single responsibility. It does not mean that your classes should only contain one method or property. Everything in the class should be related to that single purpose. This means that every class, or similar structure, in your code should have only one job to do. The Single Responsibility Principle (SRP) states that there should never be more than one reason for a class to change. Previous: The SOLID Principles The Principle
