Code quality and technical debt

Single responsibility principle

Also known as Single responsibility principle, Single responsibility principle in software engineering

By WeavePublished 1 min read

Definition

A design principle that asks a software unit to have one coherent reason to change.

What it means

The single-responsibility principle, or SRP, is about cohesive responsibility rather than a literal single operation. A class, module, or service should gather behavior that changes for a related reason. Separating unrelated reasons can make tests and reviews more focused, but the right boundary depends on the domain.

Example

A user profile class formats emails, calculates billing discounts, and writes audit logs. Each concern follows different policy changes, so the team evaluates separate collaborators or modules.

Limitations

Splitting every method into its own class can make a codebase harder to navigate. A unit may legitimately coordinate one cohesive workflow with several steps. Ask what changes together and who owns the decision.

How to use the signal

Ask what changes together and who decides it, rather than splitting a cohesive workflow into arbitrary fragments.

Weave can help compare SRP-driven refactors with pull request size, review depth, and later rework. It does not determine responsibility boundaries automatically; use the signal to focus design discussion.

How this relates to Weave

Weave can help compare SRP-driven refactors with pull request size, review depth, and later rework. It does not determine responsibility boundaries automatically; use the signal to focus design discussion.

Explore Engineering intelligence

Sources and further reading

  1. SonarSource code metrics and analysis documentation