Knowledge (XXG)

Single-responsibility principle

Source đź“ť

190:
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.
124:
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.". In some of his talks, he also argues that the principle is, in particular, about roles or actors. For
178:
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
120:, the originator of the term, expresses the principle as, "A class should have only one reason to change". 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 114:) is a computer programming principle that states that "A module should be responsible to one, and only one, actor." The term actor refers to a group (consisting of one or more stakeholders or users) that requires a change in the module. 125:
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.
280: 161:. 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." 93: 354: 256: 479: 453: 308: 421: 507: 205: 200: 184: 62: 210: 86: 67: 57: 146: 486: 325: 162: 445: 52: 79: 502: 175:, and concludes that a class or module should have one, and only one, reason to be changed (e.g. rewritten). 226: 121: 180: 437: 294: 134: 274: 215: 472: 371: 17: 449: 417: 350: 304: 262: 252: 117: 183:, and should, therefore, be in separate classes or modules. It would be a bad design to 406: 496: 413: 344: 298: 401: 150: 266: 248:
Clean architecture : a craftsman's guide to software structure and design
246: 346:
Clean Architecture: A Craftsman's Guide to Software Structure and Design
179:
says that these two aspects of the problem are really two separate
223:—the "S" in "SOLID" represents the single responsibility principle 220: 33: 187:
two things that change for different reasons at different times.
300:
Agile Software Development, Principles, Patterns, and Practices
143:
Agile Software Development, Principles, Patterns, and Practices
145:. Martin described it as being based on the principle of 137:
in his article "The Principles of OOD" as part of his
405: 442:The Practical Guide to Structured Systems Design 159:The Practical Guide to Structured Systems Design 87: 8: 408:Structured Analysis and System Specification 155:Structured Analysis and System Specification 487:The Single Responsibility Principle (2014) 480:The Single Responsibility Principle (2007) 279:: CS1 maint: location missing publisher ( 94: 80: 29: 237: 39: 32: 388: 272: 326:"The Single Responsibility Principle" 171:Martin defines a responsibility as a 7: 139:Principles of Object Oriented Design 25: 141:, made popular by his 2003 book 206:Coupling (computer programming) 201:Chain-of-responsibility pattern 108:single-responsibility principle 18:Single responsibility principle 446:Yourdon Press Computing Series 211:GRASP (object-oriented design) 27:Computer programming principle 1: 303:. Prentice Hall. p. 95. 157:, and Meilir Page-Jones in 133:The term was introduced by 524: 370:Martin, Robert C. (2005). 324:Martin, Robert C. (2014). 245:Martin, Robert C. (2018). 343:Robert C. Martin (2018). 372:"The Principles of OOD" 508:Programming principles 227:Separation of concerns 122:Separation of Concerns 473:The Principles of OOD 63:Interface segregation 48:Single responsibility 68:Dependency inversion 330:The Clean Code Blog 58:Liskov substitution 489:" by Robert Martin 482:" by Robert Martin 475:" by Robert Martin 438:Page-Jones, Meilir 216:Information hiding 149:, as described by 356:978-0-13-449416-6 349:. Prentice Hall. 295:Martin, Robert C. 258:978-0-13-449432-6 104: 103: 16:(Redirected from 515: 460: 459: 434: 428: 427: 411: 398: 392: 391:, pp. 95–98 386: 380: 379: 367: 361: 360: 340: 334: 333: 321: 315: 314: 291: 285: 284: 278: 270: 242: 181:responsibilities 173:reason to change 135:Robert C. Martin 118:Robert C. Martin 96: 89: 82: 30: 21: 523: 522: 518: 517: 516: 514: 513: 512: 503:Software design 493: 492: 468: 463: 456: 436: 435: 431: 424: 400: 399: 395: 387: 383: 376:butunclebob.com 369: 368: 364: 357: 342: 341: 337: 323: 322: 318: 311: 293: 292: 288: 271: 259: 244: 243: 239: 235: 197: 169: 131: 100: 28: 23: 22: 15: 12: 11: 5: 521: 519: 511: 510: 505: 495: 494: 491: 490: 483: 476: 467: 466:External links 464: 462: 461: 455:978-8120314825 454: 448:. p. 82. 429: 422: 393: 381: 362: 355: 335: 316: 310:978-0135974445 309: 286: 257: 236: 234: 231: 230: 229: 224: 218: 213: 208: 203: 196: 193: 168: 165: 130: 127: 102: 101: 99: 98: 91: 84: 76: 73: 72: 71: 70: 65: 60: 55: 50: 42: 41: 37: 36: 26: 24: 14: 13: 10: 9: 6: 4: 3: 2: 520: 509: 506: 504: 501: 500: 498: 488: 484: 481: 477: 474: 470: 469: 465: 457: 451: 447: 443: 439: 433: 430: 425: 423:0-13-854380-1 419: 415: 414:Prentice Hall 410: 409: 403: 402:DeMarco, Tom. 397: 394: 390: 385: 382: 377: 373: 366: 363: 358: 352: 348: 347: 339: 336: 331: 327: 320: 317: 312: 306: 302: 301: 296: 290: 287: 282: 276: 268: 264: 260: 254: 250: 249: 241: 238: 232: 228: 225: 222: 219: 217: 214: 212: 209: 207: 204: 202: 199: 198: 194: 192: 188: 186: 182: 176: 174: 166: 164: 163: 160: 156: 152: 148: 144: 140: 136: 128: 126: 123: 119: 115: 113: 109: 97: 92: 90: 85: 83: 78: 77: 75: 74: 69: 66: 64: 61: 59: 56: 54: 51: 49: 46: 45: 44: 43: 38: 35: 31: 19: 441: 432: 407: 396: 384: 375: 365: 345: 338: 329: 319: 299: 289: 247: 240: 189: 177: 172: 170: 158: 154: 153:in his book 142: 138: 132: 116: 111: 107: 105: 47: 389:Martin 2003 151:Tom DeMarco 53:Open–closed 497:Categories 267:1003645626 251:. Boston. 233:References 40:Principles 275:cite book 440:(1988). 404:(1979). 297:(2003). 195:See also 147:cohesion 167:Example 129:History 452:  420:  353:  307:  265:  255:  185:couple 221:SOLID 34:SOLID 450:ISBN 418:ISBN 351:ISBN 305:ISBN 281:link 263:OCLC 253:ISBN 106:The 112:SRP 499:: 444:. 416:. 412:. 374:. 328:. 277:}} 273:{{ 261:. 485:" 478:" 471:" 458:. 426:. 378:. 359:. 332:. 313:. 283:) 269:. 110:( 95:e 88:t 81:v 20:)

Index

Single responsibility principle
SOLID
Single responsibility
Open–closed
Liskov substitution
Interface segregation
Dependency inversion
v
t
e
Robert C. Martin
Separation of Concerns
Robert C. Martin
cohesion
Tom DeMarco

responsibilities
couple
Chain-of-responsibility pattern
Coupling (computer programming)
GRASP (object-oriented design)
Information hiding
SOLID
Separation of concerns
Clean architecture : a craftsman's guide to software structure and design
ISBN
978-0-13-449432-6
OCLC
1003645626
cite book

Text is available under the Creative Commons Attribution-ShareAlike License. Additional terms may apply.

↑