nsored Links
-->

Friday, May 25, 2018

Single responsibility principle

Single Responsibility Principle | Object Oriented Design
src: www.javabrahman.com

The single responsibility principle is a computer programming principle that states that every module or class should have responsibility over a single part of the functionality provided by the software, and that responsibility should be entirely encapsulated by the class. All its services should be narrowly aligned with that responsibility. Robert C. Martin expresses the principle as, "A class should have only one reason to change."


Video Single responsibility principle



History

The term was introduced by Robert C. Martin in an article by the same name as part of his Principles of Object Oriented Design, made popular by his book Agile Software Development, Principles, Patterns, and Practices. Martin described it as being based on the principle of cohesion, as described by Tom DeMarco in his book Structured Analysis and System Specification, and Meilir Page-Jones in The Practical Guide to Structured Systems Design.


Maps Single responsibility principle



Example

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 (i.e. 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 very different causes; one substantive, and one cosmetic. 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 greater danger that the printing code will break if it is part of the same class.


S.O.L.I.D: The First 5 Principles of Object Oriented Design ― Scotch
src: image.slidesharecdn.com


See also

  • Separation of concerns
  • Chain-of-responsibility pattern
  • Cohesion (computer science)
  • Open/closed principle
  • SOLID -- the "S" in "SOLID" stands for the single responsibility principle
  • GRASP (object-oriented design)

SOLID Unity3D - Single Responsibility Principle - YouTube
src: i.ytimg.com


References


SOLID Principles in Software Design - ppt video online download
src: slideplayer.com


External links

  • The Secret behind the Single Responsibility Principle
  • The Single Responsibility Principle

Source of the article : Wikipedia