Single responsibility principle |
In computer science, the single responsibility principle was introduced by Tom DeMarco in his book Structured Analysis and Systems Specification , Yourdon Press Computing Series, 1979. It states that every object should have a single responsibility, and that all its services should be narrowly aligned with that responsibility. The principle forms part of Cohesion, a concept widely used in software development.
Robert Cecil Martin (Uncle Bob) has re-interpreted the concept[http://www.objectmentor.com/resources/articles/srp] for OO as part of his Principles of OOD[http://www.butunclebob.com/ArticleS.UncleBob.PrinciplesOfObjectOrientedDesign], made popular by his book Agile Software Development: Principles, Patterns, and Practices [http://www.objectmentor.com/resources/bookstore/books/AgileSoftwareDevelopmentPPP].
The essence of his interpretation is that a responsibility is a reason to change , and that a class or module should have one, and only one, reason to change. As an example, consider a module that compiles and prints a report. Such a module can be changed for two reasons. First, the content of the report can change. Second, the format of the report can change. These two things change for very different causes; one subtantive, and one cosmetic. The SRP says that these two aspects of the problem are really two separate responsibilities, and should therefore be in seperate classes or modules. It would be a shame to couple two things that change for different reasons at different times.
The single responsibility principle is used in responsibility driven design methodologies like the Responsibility Driven Design (RDD) and the URDAD (URDAD).|
|