Skip to content
Commitwise
Menu

Single responsibility principle

Also called: SRP

The S in SOLID: a class should have one reason to change, meaning one group of people whose requests change it.

Definition

Code that changes for different stakeholders, such as pricing rules, storage and email wording, should live in different classes, so a change for one cannot break the others. It does not mean one method per class: a class with ten methods that all serve the same job still has a single responsibility.

In practice

An OrderService that validates, prices, saves and emails is split into a pricing policy, a repository and a notifier.

Learn it in context

Lessons that use this term.

Related terms

Esc

Type to search the whole site.