{"post":{"slug":"what-is-the-single-responsibility-principle-2026","title":"What is the single responsibility principle in 2026?","excerpt":"The single responsibility principle says a class or module should have one reason to change. Here is what that means in practice and where it gets misapplied.","category":"code","date":"July 24, 2026","author":"ByteLedger Team","content":"<span class=\"dropcap\">T</span>he single responsibility principle says a class, function, or module should have exactly one reason to change. It is the first letter in SOLID and, in practice, the most frequently violated of the five, because responsibilities creep in gradually rather than arriving all at once. A class that starts out doing one job quietly picks up a second and third over a few sprints, and nobody notices until a change in one area breaks something unrelated.\n\n## What changed in 2026\n\n- **AI-generated code tends to extend existing classes rather than create new ones.** Sticking new logic into a file that is already open is the path of least resistance for a model completing a diff, so single responsibility violations show up more often in AI-assisted pull requests unless reviewed for scope.\n- **Coupling metrics are now a normal CI check.** Static analysis that flags classes with too many collaborators or too many reasons to change has moved from academic tooling into everyday linting.\n- **The microservices retrospective landed.** After a decade of splitting systems into services, the 2026 consensus is that single responsibility still has to be applied inside each service, at the function and class level; splitting services without splitting responsibilities just moves the mess.\n\n## What one reason to change actually means\n\nRobert C. Martin later clarified the principle with an actor-based definition: a reason to change is tied to a single actor or stakeholder, not a literal count of tasks. A class with three methods can still have a single responsibility if all three exist to serve the same stakeholder and always change together. The common misreading, that a class should have exactly one method, is not what the principle says.\n\n## A concrete example\n\n```js\n// Before: three reasons to change live in one class\nclass Invoice {\n  calculateTotal() { /* ... */ }\n  formatAsHtml() { /* ... */ }\n  saveToDatabase() { /* ... */ }\n}\n\n// After: one responsibility per class\nclass Invoice { calculateTotal() { /* ... */ } }\nclass InvoiceHtmlFormatter { format(invoice) { /* ... */ } }\nclass InvoiceRepository { save(invoice) { /* ... */ } }\n```\n\nBilling logic changes when tax rules change. Formatting changes when the design team updates a template. Storage changes when the database migrates. Three stakeholders, three reasons to change, three classes.\n\n## How to spot a violation\n\n- The class name is vague, or contains \"and,\" such as `UserManagerAndValidator` or a generic catch-all like `Utils`.\n- A change request from one team consistently touches the same file as an unrelated team's changes.\n- Testing one behavior requires mocking dependencies that have nothing to do with that behavior.\n- The class grows every sprint, regardless of which feature is being built.\n\n## SRP compared to the other SOLID principles\n\n| Principle | Focuses on | How it differs from SRP |\n| --- | --- | --- |\n| Open/Closed | Extension without modification | SRP is about the scope of a responsibility; Open/Closed is about how you extend it safely |\n| Interface Segregation | Shape of a contract | Interface Segregation is SRP applied to interfaces specifically |\n| Dependency Inversion | Direction of dependencies | Orthogonal; a class can have a single responsibility and still depend on concrete classes it should not |\n\nFor the full picture of how these five fit together, see [SOLID principles explained in 2026](/blog/solid-principles-explained-2026). Once a class is properly scoped to one responsibility, [dependency inversion](/blog/what-is-dependency-inversion-2026) is usually the next thing worth fixing.\n\n## When splitting goes too far\n\nThe failure mode in the other direction is real: five classes, each with one method, spread across three files, for logic that is only ever used in one place. Tracing a single bug now means opening four files instead of one. Split along genuine axes of change, not just to hit a stylistic target of small classes. If two pieces of logic have never changed independently and there is no reason to expect they ever will, they may belong together.\n\n## FAQ\n\n**Is SRP the same as having short classes?**\nNo. A short class can still mix unrelated responsibilities, and a longer class can be perfectly cohesive if every method serves the same purpose.\n\n**How do I know if two responsibilities are actually one?**\nAsk whether they change for the same reason, driven by the same stakeholder. If they always change together, they are probably one responsibility; if they change independently, split them.\n\n**Does SRP apply to functions, not just classes?**\nYes. A function that validates input, calls an API, and formats the response has three reasons to change, the same problem at a smaller scale.\n\n**What is the difference between SRP and cohesion?**\nCohesion describes how related the elements inside a module are, in general. SRP is a specific, narrower framing of cohesion, focused on the single axis of \"who causes this to change.\"\n\n## Where to go next\n\n- [SOLID principles explained in 2026](/blog/solid-principles-explained-2026)\n- [Dependency inversion explained in 2026](/blog/what-is-dependency-inversion-2026)\n- [Interface vs abstract class in 2026](/blog/what-is-an-interface-vs-abstract-class-2026)","hue":280,"metaTitle":"Single Responsibility Principle Explained 2026","metaDescription":"The single responsibility principle in 2026: what one reason to change really means, real code examples, and when splitting a class goes too far.","keywords":["single responsibility principle 2026","srp explained","what is srp in programming","single responsibility principle example","solid principles srp","reason to change class design","srp javascript example","single responsibility vs cohesion","clean code single responsibility","srp interview question"],"tldr":["**A class or module should have exactly one reason to change** — one responsibility, one axis of change, not one method.","**Reason to change means an actor or stakeholder, not a literal count of tasks** — a class can call several methods and still have a single responsibility if they all serve the same purpose.","**The usual symptom of a violation is unrelated churn** — a change to email formatting also forces a re-test of billing logic in the same file.","**Splitting too early has a cost too** — five one-method classes for a script nobody else will touch just adds navigation overhead.","**Skip:** treating one responsibility as one method; a class can have several small methods and still be doing exactly one job."],"readTime":"4 min read","wordCount":843},"related":[{"slug":"solid-principles-explained-2026","title":"SOLID principles explained in 2026: five rules for better code","excerpt":"SOLID is five design principles for object-oriented code, from single responsibility to dependency inversion. Here is what each one means and when to skip them.","category":"code","date":"July 16, 2026","author":"ByteLedger Team","readTime":"4 min read","hue":290},{"slug":"how-to-write-clean-functions-2026","title":"How to write clean functions in 2026","excerpt":"Clean functions are the single highest-leverage thing you can do for code quality. Here is the 2026 playbook with concrete rules and real examples.","category":"code","date":"March 18, 2026","author":"ByteLedger Team","readTime":"4 min read","hue":318},{"slug":"what-is-the-event-loop-2026","title":"What is the event loop in 2026? Tracing code step by step","excerpt":"The event loop decides what runs next when your code has a call stack, a microtask queue, and a callback queue all waiting. Here is how to trace it.","category":"code","date":"July 24, 2026","author":"ByteLedger Team","readTime":"4 min read","hue":290}],"sameCategory":[{"slug":"bazel-build-explained-2026","title":"Bazel Explained: What Hermetic Builds Actually Cost","excerpt":"Bazel delivers reproducible, precisely cached builds and demands that you describe everything. Here is what you get, what it costs, and who should say no.","category":"code","date":"August 19, 2026","author":"ByteLedger Team","readTime":"3 min read","hue":145},{"slug":"graphql-federation-2026","title":"GraphQL Federation: One Graph, Many Teams","excerpt":"Federation composes independently-owned subgraphs into a single API. Here is what it solves, the operational cost it adds, and when a simpler gateway is enough.","category":"code","date":"August 19, 2026","author":"ByteLedger Team","readTime":"3 min read","hue":300},{"slug":"hermetic-builds-explained-2026","title":"Hermetic Builds Explained: Same Inputs, Same Output","excerpt":"A hermetic build depends only on declared inputs. Here is what that property gives you, the common leaks that break it, and how to move toward it incrementally.","category":"code","date":"August 19, 2026","author":"ByteLedger Team","readTime":"3 min read","hue":130},{"slug":"monorepo-tooling-compared-2026","title":"Monorepo Tooling Compared: What You Actually Need","excerpt":"Monorepo tools solve task orchestration and caching, not repository layout. Here is what each tier provides and how to tell when you have outgrown the simple option.","category":"code","date":"August 19, 2026","author":"ByteLedger Team","readTime":"3 min read","hue":150}],"newer":{"slug":"what-is-the-event-loop-2026","title":"What is the event loop in 2026? Tracing code step by step","excerpt":"The event loop decides what runs next when your code has a call stack, a microtask queue, and a callback queue all waiting. Here is how to trace it.","category":"code","date":"July 24, 2026","author":"ByteLedger Team","readTime":"4 min read","hue":290},"older":{"slug":"what-is-thermal-paste-2026","title":"What Is Thermal Paste? The 2026 Application Guide","excerpt":"Thermal paste fills the microscopic gaps between a chip and its cooler so heat can transfer properly. Here is what it does, when to reapply it, and how to apply it correctly in 2026.","category":"tech","date":"July 24, 2026","author":"ByteLedger Team","readTime":"3 min read","hue":215}}