← Back to results

Single-responsibility principle - Wikipedia Jump to cont

ent Main menu Main menu move to sidebar hide Navigation Main page Contents Current events Random article About Wikipedia Contact us Contribute Help Learn to edit Community portal Recent changes Upload file Special pages Print/export Download as PDF Printable version In other projects Wikidata item Search Search Appearance Donate Create account Log in Personal tools Donate Create account Log in Contents move to sidebar hide (Top) 1 History 2 Example 3 See also 4 References 5 External links Toggle the table of contents Single-responsibility principle 21 languages العربية Беларуская Català Čeština Deutsch Español فارسی Français Magyar Italiano 日本語 한국어 Polski Português Русский Slovenščina Svenska Türkçe Українська Tiếng Việt 中文 Edit links Article Talk English Read Edit View history Tools Tools move to sidebar hide Actions Read Edit View history General What links here Related changes Upload file Permanent link Page information Cite this page Get shortened URL Print/export Download as PDF Printable version In other projects Wikidata item Appearance move to sidebar hide From Wikipedia, the free encyclopedia (Redirected from Single responsibility principle ) Computer programming principle SOLID Principles Single responsibility Open–closed Liskov substitution Interface segregation Dependency inversion v t e The single-responsibility principle ( SRP ) is a computer programming principle that states that "A module should be responsible to one, and only one, actor." [ 1 ] The term actor refers to a group (consisting of one or more stakeholders or users) that requires a change in the module. Robert C. Martin , the originator of the term, expresses the principle as, "A class should have only one reason to change". [ 2 ] Because of confusion around the word "reason", he later clarified his meaning in a blog post titled "The Single Responsibility Principle", in which he mentioned Separation of Concerns and stated that "Another wording for the Single Responsibility Principle is: Gather together the things that change for the same reasons. Separate those things that change for different reasons." [ 3 ] In some of his talks, he also argues that the principle is, in particular, about roles or actors. For example, while they might be the same person, the role of an accountant is different from a database administrator. Hence, each module should be responsible for each role. [ 4 ] History [ edit ] The term was introduced by Robert C. Martin in his article "The Principles of OOD" as part of his Principles of Object Oriented Design , [ 5 ] made popular by his 2003 book Agile Software Development, Principles, Patterns, and Practices . [ 6 ] Martin described it as being based on the principle of cohesion , as described by Tom DeMarco in his book Structured Analysis and System Specification , [ 7 ] and Meilir Page-Jones in The Practical Guide to Structured Systems Design . [ 8 ] In 2014 Martin published a blog post titled "The Single Responsibility Principle" with a goal to clarify what was meant by the phrase "reason for change." [ 9 ] Example [ edit ] Martin defines a responsibility as a reason to change , and concludes that a class or module should have one, and only one, reason to be changed (e.g. rewritten). As an example, consider a module that compiles and prints a report. Imagine such a module can be changed for two reasons. First, the content of the report could change. Second, the format of the report could change. These two things change for different causes. The single responsibility principle says that these two aspects of the problem are really two separate responsibilities , and should, therefore, be in separate classes or modules. It would be a bad design to couple two things that change for different reasons at different times. The reason it is important to keep a class focused on a single concern is that it makes the class more robust. Continuing with the foregoing example, if there is a change to the report compilation process, there is a greater danger that the printing code will break if it is part of the same class. See also [ edit ] Chain-of-responsibility pattern Coupling (computer programming) GRASP (object-oriented design) Information hiding SOLID —the "S" in "SOLID" represents the single responsibility principle Separation of concerns References [ edit ] ^ Martin, Robert C. (2018). Clean architecture : a craftsman's guide to software structure and design . Boston. ISBN   978-0-13-449432-6 . OCLC   1003645626 . {{ cite book }} : CS1 maint: location missing publisher ( link ) ^ Martin, Robert C. (2003). Agile Software Development, Principles, Patterns, and Practices . Prentice Hall. p. 95. ISBN   978-0135974445 . ^ Martin, Robert C. (2014). "The Single Responsibility Principle" . The Clean Code Blog . ^ Robert C. Martin (2018). Clean Architecture: A Craftsman's Guide to Software Structure and Design . Prentice Hall. ISBN   978-0-13-449416-6 . ^ Martin, Robert C. (2005). "The Principles of OOD" . butunclebob.com . ^ Martin 2003 , pp. 95–98 ^ DeMarco, Tom. (1979). Structured Analysis and System Specification . Prentice Hall . ISBN   0-13-854380-1 . ^ Page-Jones, Meilir (1988). The Practical Guide to Structured Systems Design . Yourdon Press Computing Series . p. 82. ISBN   978-8120314825 . ^ "Clean Coder Blog" . blog.cleancoder.com . External links [ edit ] " The Principles of OOD " by Robert Martin " The Single Responsibility Principle (2007) " by Robert Martin " The Single Responsibility Principle (2014) " by Robert Martin Retrieved from " https://en.wikipedia.org/w/index.php?title=Single-responsibility_principle&oldid=1310638610 " Categories : Software design Programming principles Hidden categories: CS1 maint: location missing publisher Articles with short description Short description is different from Wikidata This page was last edited on 10 September 2025, at 20:10  (UTC) . Text is available under the Creative Commons Attribution-ShareAlike 4.0 License ; additional terms may apply. By using this site, you agree to the Terms of Use and Privacy Policy . Wikipedia® is a registered trademark of the Wikimedia Foundation, Inc. , a non-profit organization. Privacy policy About Wikipedia Disclaimers Contact Wikipedia Legal & safety contacts Code of Conduct Developers Statistics Cookie statement Mobile view Search Search Toggle the table of contents Single-responsibility principle 21 languages Add topic