0

This is more of an OOD problem and I have no specific code to post here. Can the same class violate the SRP in one context and be SRP compliant in other without changing a single line of a code?

In other words, can there be a situation that within the frameworks of the former requirements the class is SRP compliant and now, when requirements are changed it isn't compliant any more.

x86-Debug
  • 65
  • 4
  • 1
    An example of a class and two different contexts that illustrate the problem would be really helpful here. – Adrian Hofman Sep 05 '16 at 03:19
  • @AdrianHofman What a powerful comment. ;) If I could give a single example of how the same class is SRP compliant in one context and not compliant in other, I would not ask this question, as a single example is enough to prove that yes, it is possible. – x86-Debug Sep 05 '16 at 03:37
  • You should post this on programmers instead of SO. They deal with the more "conceptual" questions. – Euphoric Sep 05 '16 at 06:04
  • can you give example from real life use ? – Leon Barkan Sep 05 '16 at 06:43
  • @x86-Debug touché :) it's a difficult question, so some context or other information would be helpful. What's prompting your question? – Adrian Hofman Sep 05 '16 at 11:05

1 Answers1

3

It kinda comes down to how nebulous the the SRP actually is. What it actually means is: class should be a cohesive combination of behaviors, which all has only a single reason for change. These behaviors must be such that they belong together and it would be unnatural to remove any of them. This has nothing to do with the context in which you use the class.

TL;DR: no

tereško
  • 58,060
  • 25
  • 98
  • 150