The Single Responsibility Principle
"There should never be more than one reason for a class to change."
"There should never be more than one reason for a class to change."
A unit of code should answer to one constituency. If a tax rule and a page layout can each force you to edit the same class, that class serves two masters and every change made for one risks breaking the other.
Rated Heuristic: a dependable rule of thumb, not a proven theorem. The other 224.
The unit of the principle is the reason, not the line count, and a reason traces back to a person or role who can ask for a change. When two reasons live in one module, an edit made on behalf of one of them must be tested against the other, because they share state, share the file and share the deployment. The coupling is organisational before it is technical: two groups now have a shared point of contention that neither chose. Splitting on the axis of who asks for changes puts each group's edits in a place where nobody else's work can be broken by them.
It is the first and most quoted of the SOLID principles, and the one that gives 'this class does too much' a testable meaning: not too many lines, but too many people who can demand a change to it. Read that way it is a claim about organisations as much as about code, and it is the bridge between design advice and Conway's Law.
'One reason to change' cannot be decided from the code, only from a forecast of what the organisation will ask for next, and that forecast is exactly what nobody has. The principle also has no natural stopping point: taken to its limit it produces a class per method, a design its own advocates reject but the wording does not exclude. Martin later reformulated it around actors rather than reasons partly because the original phrasing was so widely read as a licence to fragment.
It does not say a class should do only one thing, and it is not a rule about size. A large class with one reason to change satisfies it; a three-line class serving two masters does not. It is also not an argument against classes that coordinate several collaborators — coordination can itself be the single responsibility.
Real as a rule of thumb, not as a theorem. The Single Responsibility Principle is rated Heuristic here: dependable enough to plan with, and with no proof behind it.
Rated from two sources. 225 of the 1,116 entries carry this rating. How the scale works.
The best-known laws are the least likely to rest on measurement; the full verdict on The Single Responsibility Principle.
Stated by Robert C. Martin, who collected it with four others in his 2000 paper "Design Principles and Design Patterns" and made it the S of the SOLID set. Martin credits the underlying idea of cohesion to earlier structured-design work, and has since restated the principle in terms of actors: gather together the things that change for the same reason, and separate those that change for different reasons.
Everything above traces to web.archive.org and en.wikipedia.org, two sources in all, one of them the original publication rather than an account of it. Nothing is written from memory, and the method is written down. Spot an error or a better source? Suggest a fix.