ArticleS. DavidChelimsky.
SingularResponsibility [add child]

Singular Responsibility


There is a section in our refactoring classes where we talk about duplication being a violation of the Single Responsibility Principle. The idea being that if one responsibility is expressed in two places, each place only manages 1/2 of the responsibility. So you end up with less-than-single responsibility.

This is another way to express DRY (don't repeat yourself), but I like the idea of thinking of it as a sibling of sorts to Single Responsibility.

In my search for ways to talk about and clarify this, I've started using the term "Singular Responsibility". So "Single Responsibility" tells us that objects should have only one responsibility, and "Singular Responsibility" tells us that each class should be the one and only home for a given responsibility within a system.


!commentForm
 Thu, 18 May 2006 13:57:53, Tim Ottinger, Back in the day...
In the old days all of us old farts used to talk about conceptual "centers". Not only does each responsibility have only one home, each home should have one responsibility. It is the single home of a single responsibility. We wrote more, simpler classes than our peers.

Strangely enough, the database folks beat us to this punch with their normal forms. Each table represents one thing, the whole thing, and nothing but the thing. This is "object normalization".

In some code bases, though, I'm happy enough to be able to figure out any purpose for some of the classes <.5 wink>.
 Thu, 18 May 2006 13:57:54, Dave Hoover, would Sole Responsibility be clearer?
 Thu, 18 May 2006 14:19:37, David Chelimsky, Sole responsibility
Thanks Dave - I like Single/Singular because it's, well, cute. But Single/Sole makes the distinction that I'm looking for in a less confusing way. Don't be surprised if this blog gets renamed!
 Thu, 18 May 2006 16:47:17, Ilja Preuß, Single Choice Principle?
I think I've somewhere read about this as the Single Choice Principle - the fact that if you want to know or change something, there should be exactly one place to look at.
 Sat, 20 May 2006 01:20:32, David Chelimsky, other ideas
It occurs to me that "Sole Responsibility" is the same (from a spoken language perspective) as "Single Responsibility".

How about "Single Home" or "Single Location" (based on Tim's feedback)?
 Sun, 21 May 2006 10:22:55, Tim Ottinger, Primary Sources
The original text of the Single Responsibility Principle was "A class has a single responsibility. It does it all, it does it well, and it does it only."

That's more complete than the form we've taken to using "A class has only one reason to change" which is derivative, and somehow makes me lonely for the original. I think that the version we have seems to say something different than the original version, something very right but not entirely the same.

I think that the "reason to change" is a corrolary. There's a feel there that there are things whose reasons and rates of change are different. The class should not have to change wrt one responsibility at a different rate than for a different responsibility -- it should have only one. In Michael's playing with physics as software design, we're trying to avoid torque when one "side" of the class is moving faster than the other side.

But I'd be happy for the original name to carry the original meaning, and for these secondary effects & symptoms to be subsumed in it.
 Mon, 22 May 2006 07:15:08, David Chelimsky, does it all
DOH! Of course "does it all" covers this idea. OK. No additional names then.

Thanks!