Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

Consider two UI designers who want to design "user attractive" designs. "User attraction" is a concept that is not objective and only resides in the mind of designers. Thus designer A could for example pick up red color, while designer B picks blue. Designer A create a layout which is entirely different from designer B, and so on.

I read about SRP (Single Responsibility Principle) and what I understood was kind of a subjective analysis or break down of responsibilities that can vary from an OO designer to another OO designer. Am I right? In other words, is it possible to have two excellent object oriented analyzer and designer who come up with two different designs for one system based on SRP principal?

share|improve this question
2  
I think any kind of design (art, engineering, ...) has a balance of objectivity and subjectivity - some clear rules and constraints, some experience and judgement calls, and even some completely free all-options-as-good-as-each-other choices. –  Steve314 Aug 6 '11 at 12:04
add comment

5 Answers

up vote 8 down vote accepted

A good question and one I used to often mull over.

I would say not objective, no. Definitely subjective. How you approach breaking down problems depends on your philosophy toward that type of problem. Science shows us that there can be many different ways to solve the same problem effectively. Science also shows us that people continents apart can come up with the same solutions independently, and so some solutions are more obvious than others. In any case, judging solutions in terms of "best" depends on your criteria.

Really, what one might see as two parts of the same whole, another might see as two totally separate concepts. One sees this all the time when looking at how maintainers of different code libraries approach the same problem. And yet both solutions work just fine.

(PS. Edited this answer as the OP's final question asks the opposite of the question title.)

share|improve this answer
add comment

SRP is objective; implementations are subjective

two implementations with the exact same functionality may use completely different internal structures, which results in different classes and method, and both can satisfy SRP

if they use the same methods and state, and both are normalized (minimal/nonredundant) then they will - in theory - end up with the same classes and methods under SRP.

but I can't prove it. Yet.

share|improve this answer
add comment

The application of the principle is subjective. However, "subjective" does not equate to "preference" the same way aesthetics do.

There are obvious extremes. A class with exactly one method, with only a few lines of code, which does not call out to any other classes, is definitely following the SRP. On the other hand, a class with two methods, one which contains a complete e-mail implementation through raw sockets and another which builds up a GUI form, is definitely not following the SRP.

Aesthetics are a poor analogy. A better analogy would be the well-known computer science concepts of coupling and cohesion. Neither of these are black-and-white, true-or-false attributes. However, they are measurable, even if there's a qualitative element. If you show a group of experienced developers two separate designs for the same feature, they are going to give similar readings on which design has more coupling and/or cohesion.

In fact, the SRP is essentially just functional cohesion. It says that the parts of some module (e.g. class) should be grouped together because they all contribute to performing the same function, and for no other reason. "Function" may be subject to interpretation - some people may interpret this literally as a single function (or method or procedure) declaration, others may step back a bit and think of a function as "sending e-mail" or "playing music", but there is still only so much room to maneuver. "Managing stuff" is not a valid functional description.

share|improve this answer
add comment

There's an objective definition of the "responsibility" as a "reason to change". In the time of the programming all the reasons to change lie in the future, so the programmer can only guess based on their experience and domain knowledge. So analyzing the responsibilities is a sort of forecast, partly subjective.

share|improve this answer
add comment

The principle itself is objective, but there are so many different ways of implementing something that follows the principle, that two independent developers will almost always come up with rather different system designs for the same application.

It's even likely that the same developer doing the same design twice, will still come up with two solutions that at least partially differ.

For a principle to cause system designs to always look the same, it would have to cover every aspect of the design decisions. The single responsibility principal only covers a small part of the design decisions involved in making any system design.

share|improve this answer
    
Good analysis @Guffa. +1. I liked the idea of not being all-encompassing. Yeah, SRP only tells you to try to make everything responsible for one issue. But it doesn't tell you where the boundary of responsibility is. –  Saeed Neamati Aug 6 '11 at 12:29
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.