الانتقال إلى المحتوى
Software ArchitectureSOLID· 7 دقائق للقراءة

Single Responsibility Doesn't Mean 'Do One Thing'

Robert C. Martin's SRP is about who asks for a change. 'Do one thing' is a different rule, written for functions.

ReadIn

مقال كل يوم يفرق معاك

21 نوفمبر 2026
  • كاتب موثّق
محتويات المقال

Payroll asks for a new rule: overtime now starts after 40 hours a week. A developer updates the RegularHours() helper in the Employee class, the pay tests pass, and the change ships. At the end of the month the operations team escalates: the hours report their auditors rely on shows different numbers, and nobody asked for that. The class was small and every method "did one thing", yet a change for one department still broke another department's work.

The common misconception

The belief: SRP means a class, or a method, should do only one thing. A class with CalculatePay, ReportHours and Save does three things, so split it; a class with a single public method follows SRP by definition.

It's easy to see where this comes from. The name invites it: "single responsibility" sounds like "one job". Martin has also long given a similar-sounding rule for functions; in a 2009 post he writes that "functions should do one thing. They should do it well. They should do it only." Same author, similar words, so the two rules blur. And many summaries, including Microsoft's architecture guide, describe SRP as objects having "only one responsibility", which reads naturally as "one task".

The half-truth: small, focused functions are good advice. It just isn't the Single Responsibility Principle, and following it doesn't prevent the bug above.

What actually happens

One reason to change, and reasons are people

Martin's 2014 post states the as: each software module should have "one and only one reason to change". Then he asks the obvious question: what counts as a reason to change? Not bug fixes or refactorings; those are the programmer's job, not the program's. His answer: "This principle is about people." A module is responsible to the group that specifies its behavior. Pay rules come from finance, the audit report from operations, the database schema from the technical team. His own example uses the CFO, the COO and the CTO.

So the SRP question isn't "how many things does this class do?" It's "how many different groups could ask me to change it?"

"Do one thing" is a different rule at a different scale

The function rule is about size and readability: if you can extract a smaller, well-named function from a function, it was doing more than one thing. In that 2009 post Martin takes it as far as it goes: "Extract till you drop." You can follow it perfectly and still break SRP. Employee can be built from one-line methods and still answer to three departments. And a class with a dozen methods can respect SRP, as long as one group asks for all of them.

It's cohesion and coupling, restated

Martin offers a second wording: "Gather together the things that change for the same reasons. Separate those things that change for different reasons." He adds that this is just another way to define and . The idea is older than SOLID: Martin opens his post with David Parnas's 1972 advice to start from "design decisions which are likely to change" and design each module "to hide such a decision from the others."

Why mixing groups hurts

When one module serves several groups, shared code becomes a channel for surprises. Martin's example: change calculatePay, accidentally break reportHours, and the COO starts demanding that you never change calculatePay again. In his 2020 follow-up he adds that microservices don't solve this: you can create a tangled service, or a tangled set of services, by mixing code that changes for different reasons.

The fix: split by who asks, not by verb

C#
// One class, three audiences: finance, auditors, the database teampublic sealed class Employee(TimeCard card, decimal rate){    // Finance changed this to "overtime after 40 hours a week"    private decimal RegularHours() => Math.Min(card.WeeklyHours, 40m);    public decimal CalculatePay() =>        RegularHours() * rate        + (card.WeeklyHours - RegularHours()) * rate * 1.5m;    // The auditors' report reuses finance's helper,    // so finance's change moved the auditors' numbers too    public string ReportHours() =>        $"{card.EmployeeId}: {RegularHours()} regular hours";    public void Save(IEmployeeStore store) => store.Save(card);}

Finance's rule and the auditors' rule now live in two classes, each answering to one group, and they share only the TimeCard data. Saving moves to the persistence code behind IEmployeeStore, because the schema changes for technical reasons. Both classes compute "regular hours", which looks like duplication. It isn't: a 40-hour threshold and contracted hours are different rules that happened to agree, and they will change on different days for different people. Notice what we didn't do: split PayCalculator into RegularHoursCalculator, OvertimeCalculator and PayAssembler. Those pieces always change together, at finance's request, so splitting them would scatter one responsibility over three files.

MythReality
SRP means a class does one thingSRP means one reason to change, and Martin says reasons to change are people
A class with one method follows SRPOne method can still mix rules from two groups, like pay and audit logic
More, smaller classes means better SRPSplitting one group's rules across many classes scatters a single responsibility
"Do one thing" and SRP are the same rule"Do one thing" is Martin's rule for functions; SRP is about modules and who they serve
Microservices give you SRP for freeMartin: a service can be tangled too when it mixes code that changes for different reasons

How to apply it in your project

  1. Name the actorsFor each important class, write down who asks for changes to it: a team, a role, a regulator. One name is a good sign. Two or more makes it a candidate for a split.
  2. Find helpers shared between actorsPrivate methods or utilities called by code that serves different groups, like RegularHours(), are where one group's change leaks into another group's results.
  3. Split along actors, not verbsMove each group's rules into its own class or module and let them share only data. Accept that two rules may look alike for now.
  4. Keep "do one thing" for functionsInside each class, keep extracting small, well-named functions. That's readability work, and it doesn't change who the class answers to.

Key takeaways

  • SRP says a module should have one reason to change, and Martin says reasons to change are people.
  • "Do one thing" is a separate rule for functions; following it doesn't guarantee SRP.
  • Gather code that changes for the same reasons and separate code that changes for different reasons: that's cohesion and coupling.
  • A helper shared by two groups' code is how one team's request breaks another team's feature.
  • Don't split one group's rules into many tiny classes; that scatters a single responsibility.

📚 المصادر

  1. The Single Responsibility Principle — Robert C. Martin, The Clean Code Blog (2014)
  2. One Thing: Extract till you Drop — Robert C. Martin (2009)
  3. Solid Relevance — Robert C. Martin, The Clean Code Blog (2020)
  4. Architectural principles — .NET Architecture Guides, Microsoft Learn

التعليقات (0)