Single responsibility principle

The single responsibility principle (SRP) states that a class or module should have one, and only one, reason to change. A responsibility is a reason to change, so the principle asks that each module answer to a single actor – the person or group that would demand a change to its behavior.

SRP is the S in SOLID, a set of design principles for object-oriented programming. It is closely related to cohesion: a module with a single responsibility is by definition highly cohesive, and vice versa. It is also a specific application of separation of concerns, narrowing that broader principle to the unit of a single class or module.

The principle is often misread as "do one thing", which leads to over-decomposition. Robert C. Martin later clarified that the unit of responsibility is the actor – the stakeholder whose interests are served by the module. Two methods that serve different actors are two responsibilities, even if they appear to do similar work. Conversely, several methods that serve the same actor can belong together in one module.

Following SRP keeps modules smaller and easier to change, test, and reuse, and it reduces the chance that a change requested by one actor inadvertently breaks behavior that another actor depends on. The other SOLID letters build on this foundation: open-closed and dependency inversion are easier to achieve when modules have a single reason to change.