Using “Uncle Bob” and “Sandi Metz” as figureheads of each style because they’ve both written about them, not necessarily to imply any ownership of the concepts.
- Uncle Bob: “Each module has a single responsibility TO SOMEONE”
- If this applies at the class level, it can’t be usefully used at the method level
- Sandi Metz: “Each class/method has a single responsibility FOR SOMETHING”
- This implies the same test applied at two different levels of abstraction because the class’s responsibility is composed of the responsibilities of the methods
- How many people could be fired because of a mistake specifying this module? If more than one person, you have a violation.
- Personification: “Mr Gear, what is your ratio?”
If the question doesn’t make sense, you might have an SRP violation
- OR you might just have a misnamed class, this is not a clear test. Should your first instinct be to reach for a renaming, or Extract Method?
- Description: “What this class does is xxx AND yyy” <- “and” implies violation
- Admits weasel words. “This class represents a user” means very little. We need more defined rules to construct the description.
Not finding a violation via either of these tests doesn’t mean you have a class with a single responsibility. They admit false negatives.