Single responsibility principle

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.pdf] for OO as part of his "Principles of Object Oriented Design" [http://www.butunclebob.com/ArticleS.UncleBob.PrinciplesOfOod] , made popular by his book "Agile Software Development: Principles, Patterns, and Practices".

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 substantive, and one cosmetic. The SRP 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.

The single responsibility principle is used in responsibility driven design methodologies like the Responsibility Driven Design (RDD) and the Use Case / Responsibility Driven Analysis and Design (URDAD).

ee also

* Separation of concerns
* Chain-of-responsibility pattern
* Cohesion (computer science)


Wikimedia Foundation. 2010.

Игры ⚽ Нужно решить контрольную?

Look at other dictionaries:

  • Single Responsibility Prinzip — Das Single Responsibility Prinzip (SRP, dt. Eine Verantwortlichkeit Prinzip) ist eine Design Richtlinie in der Software Architektur. In der objektorientierten Programmierung sagt SRP aus, dass jede Klasse nur eine fest definierte Aufgabe zu… …   Deutsch Wikipedia

  • Responsibility — may refer to:* Responsibility assumption, in spirituality and personal growth * Cabinet collective responsibility, a constitutional convention in governments using the Westminster System * Collective responsibility (doctrine), a doctrine that… …   Wikipedia

  • Chain-of-responsibility pattern — In Object Oriented Design, the chain of responsibility pattern is a design pattern consisting of a source of command objects and a series of processing objects. Each processing object contains a set of logic that describes the types of command… …   Wikipedia

  • Single Convention on Narcotic Drugs — Infobox Treaty name = Single Convention on Narcotic Drugs long name = image width = 200px caption = Governments of opium producing Parties are required to purchase and take physical possession of such crops as soon as possible after harvest to… …   Wikipedia

  • Responsibility for the Holocaust — Historians differ as to where the responsibility for the Holocaust lies. Intentionalist historians such as Lucy Dawidowicz argue that Hitler planned the extermination of the Jewish people from as early as 1918, and that he personally oversaw its… …   Wikipedia

  • Moral responsibility — For other types of responsibility, see Responsibility (disambiguation). Part of a series on Freedom …   Wikipedia

  • Individual ministerial responsibility — Ministerial responsibility or individual ministerial responsibility is a constitutional convention in governments using the Westminster System that a cabinet minister bears the ultimate responsibility for the actions of their ministry or… …   Wikipedia

  • Collective responsibility (doctrine) — Collective responsibility is a concept or doctrine, according to which individuals are to be held responsible for other people s actions by tolerating, ignoring, or harboring them, without actively collaborating in these actions.This concept is… …   Wikipedia

  • Country of origin principle — For a discussion of labelling and marketing products according to their place of manufacture, see Country of origin. The country of origin principle is a principle in the law of the European Union for resolving conflict of laws between Member… …   Wikipedia

  • Collective responsibility — Not to be confused with Collective guilt. For the British Parliamentary discipline, see Cabinet collective responsibility. For other types of responsibility, see Responsibility (disambiguation). Collective responsibility is a concept or doctrine …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”