# The Single Responsibility Principle

> There should never be more than one reason for a class to change.

**Field:** Software & systems · **Reliability:** Heuristic · **Coined:** 2000 · **Named after:** Robert C. Martin

*Also known as: SRP; One reason to change*

## What it means

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.

## How it works

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.

## Examples

- **The report that also calculates:** Martin's own framing: a class computing pay and formatting a payslip answers to accounting and to presentation. A layout tweak now needs the payroll tests run.
- **The model that persists itself:** An object holding business rules and its own SQL changes both when the rules change and when the schema does: two teams, two release cadences, one file.
- **The utility bucket:** A Helpers class accretes functions with nothing in common. It has as many reasons to change as it has functions, and every one of them is a merge conflict.

## Why it matters

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.

## Where it breaks down

'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.

## Common misreadings

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.

## Origin

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.

## Related

- [SOLID](https://conyso.com/lawtome/laws/solid/) — kindred
- [Separation of Concerns](https://conyso.com/lawtome/laws/separation-of-concerns/) — kindred
- [Conway's Law](https://conyso.com/lawtome/laws/conways-law/) — kindred
- [The DRY Principle](https://conyso.com/lawtome/laws/dry/) — kindred

## Sources

- [Martin, R. C. (2000). "Design Principles and Design Patterns." — the principle as first collected, with the payroll example.](<https://web.archive.org/web/20150906155800/http://www.objectmentor.com/resources/articles/Principles_and_Patterns.pdf>)
- ["SOLID." Wikipedia — the canonical wording, 'there should never be more than one reason for a class to change', and its place in the set.](<https://en.wikipedia.org/wiki/SOLID>)

---
Source: https://conyso.com/lawtome/laws/the-single-responsibility-principle/ · The Law Tome — a sourced index of named laws.
