rightchat.blogg.se

Violation of single responsibility principle
Violation of single responsibility principle






violation of single responsibility principle

Its purpose is to help developers group functionality into appropriate classes. The key here is there must be a single reason to change.įundamentally, the SRP principle is therefore a class sizing principle. Furthermore, the word "responsibility" is bizarrely defined as a "reason to change". So the "size" of the class, for example, is not a factor in complying or breaking the SRP. In the context of the Single Responsibility Principle (SRP) we define a responsibility to be “a reason for change.” If you can think of more than one motive for changing a class, then that class has more than one responsibility. This is intriguing, so let's dig a bit further: Uncle Bob's Single Responsibility Principle states thatĪ class should have one, and only one, reason to change. In turn, they can't agree on what constitutes the appropriate size and thus can't reach an agreement. The other possibility would be that different programmers have a different understanding of the principle or how it is presented. Also, for a class to have the wrong size, there must be an objective measurement of the size, and this should eliminate pointless arguments. While this sometimes happens, I would expect any reasonably competent developer who is aware of the SRP to only make this kind of mistakes in exceptional cases and not in a fundamental manner.

violation of single responsibility principle

People are wrong all the time: maybe I was wrong and he was right or vice versa. The first possibility is that the classes are actually the wrong size. How can we explain this disagreement? Let's assume that we both know the SRP and try to apply it at the best of our abilities: I can only see two alternatives. My feedback to his patches was often the opposite, that his classed did too little and lacked cohesion.

VIOLATION OF SINGLE RESPONSIBILITY PRINCIPLE CODE

During code reviews, his feedback would often be that my classes "tried to do too much" and broke the single responsibility principle. I once worked with a colleague, whom we shall call Stan, who had a very different understanding of the single responsibility principle than I had. Did you ever happen to disagree with a colleague on the single responsibility principle and its application? Let's try to understand why that could be the case.








Violation of single responsibility principle