Single Responsibility Principle

In object-oriented programming, the single responsibility principle states that every object should have a single responsibility, and that responsibility should be entirely encapsulated by the class. All its services should be narrowly aligned with that responsibility.

The term was introduced by Robert C. Martin in an article by the same name as part of his Principles of Object Oriented Design,[1] made popular by his book Agile Software Development, Principles, Patterns, and Practices[2]. Martin described it as being based on the principle of cohesion, as described by Tom DeMarco in his book Structured Analysis and Systems Specification[3].

Martin defines a responsibility as a reason to change, and concludes 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 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.

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).

[edit] See also

About eagle081183

Passionate, Loyal
This entry was posted in C#, Integration, Programming, Software architecture. Bookmark the permalink.

One Response to Single Responsibility Principle

  1. eagle081183 says:

    List bestSeller = endecaHelper.GetBestSellerProducts(5);

    viewData[“RecentlyViewedDefaultContent”] = (from c in bestSeller select new SearchResultItem { Title = productHelper.GetSkuTitle(c), AltImageText = widgetUtilities.GetProductImageAltTags(productHelper.GetSkuTitle(c)), Image = Scene7.GetUrl(c.VendorSKU.ToString(), ViewType.White, Alt.SHOPCALLOUT) }).ToList();

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s