
- #UNCLE BOB SINGLE RESPONSIBILITY PRINCIPLE HOW TO#
- #UNCLE BOB SINGLE RESPONSIBILITY PRINCIPLE SOFTWARE#
How many responsibilities does it have? I see at least four dependencies. send a "ChargeCard" request to the terminal Calculating Responsibilities on the Example Imagine the problems which are caused by SRP violation. We discussed the SRP, but you might wonder how the concrete problems look like in real life caused by SRP violation. We refactor out different responsibilities to classes, and then we separate classes by their responsibilities into different modules or assemblies if you wish. Sometimes we find SRP violations at function’s level. So, SRP can be applied at different levels: at the function level, object level and at the module level. Modules should have only one logical responsibility. A class should do one thing, and do it well!īy the way, the same principle can be applied at the level of modules. So, applying SRP, we want to separate different concerns. If that class deals with salary reports in addition, then we have two axes since accountants are those who can request changes to reports.Īpparently, the more responsibilities a class has, the more likely it’s going to be changed. For example, if a class deals with a database, then we have one axe since DB architects are those users who can request changes. Understanding that, we can calculate how many axes of change a class has. We also can view the responsibilities of a class from the perspective of its users. For example, if a class implements logging and caching on its own, then it has at least two responsibilities.

It might be simpler to understand it as axes of changing requirements. The responsibilities of a class can be treated as axes of change. Sounds much clearer, though it still needs further clarification. “There should never be more than one reason for a class to change”. Robert Martin aka “Uncle Bob” clarified this definition by saying that Such definitions are not very helpful from the practical perspective.

#UNCLE BOB SINGLE RESPONSIBILITY PRINCIPLE HOW TO#
#UNCLE BOB SINGLE RESPONSIBILITY PRINCIPLE SOFTWARE#
Software Architecture: Meta and SOLID Principles in C#.
