0

I am quite confused about the responsibility-driven design concept. Mainly because of ever so slightly changing definitions depending on the source.

Quoting BlueJ (the book I am learning that teaches Java):

Responsibility-driven design expresses the idea that each class should be responsible for handling its own data. Often, when we need to add some new functionality to an application, we need to ask ourselves in which class we should add a method to implement this new function. Which class should be responsible for the task? The answer is that the class that is responsible for storing some data should also be responsible for manipulating it.

Later, in a "concept box" in the BlueJ book:

Reponsibility-driven design is the process of designing classes by assigning well-defined responsibilites to each class. This process can be used to determine which class should implement which part of an application function.

This second definition confuses me, as I don't see how that correlates to the first "definition"; the one saying that "it expresses the idea that each class should be responsible for handling its own data".

Will someone please shed some light on the concept of responsibility-driven design?

1
2

The class responsibility means the purpose of a class expressed in terms of things that it should take care of.

The term emerged with the CRC cards (Class, Responsibility, Collaboration), an XP technique that was presented the first time in 1989 by Beck & Cunningham in a paper about teaching object oriented thinking:

Responsibilities identify problems to be solved. The solutions will exist in many versions and refinements. A responsibility serves as a handle for discussing potential solutions. The responsibilities of an object are expressed by a handful of short verb phrases, each containing an active verb. The more that can be expressedby these phrases, the more powerful and concise the design. Again, searching for just the right words is avaluable useof time while designing.
- Kent Beck & Ward Cunningham (OOPSALA 1989)

The goal it to have clear boundaries in the collaborations, about what class does what. Your second definition is exactly about this, expressed in a compact and elegant way.

Your first definition is not incorrect but misleading. In fact, it's not a definition, it's the practical consequence of responsibility driven design, combined with elementary OO practices:

  • each class should have the data it needs and be in charge of its own data;
  • data should anyway be encapsulated, so that the class should manipulate the data belonging to its responsibility;
  • if one class starts to get too much interested in data of other classes, it'sfeature envy, which is a symptom of fuzzy boundaries in the class responsibilities (and in addition probably missing encapsulation as well).

Caution: "responsibility" means different things to different persons. In the OO literature, you'll also find the "Single Responsibility Principle (SRP)". Be aware that the naming of this principle is confusing, since the responsibility meant in the SRP has nothing to do with the responsibility OF the class but deals with the responsibility FOR the class.

6
  • So, in other words, Responsibility-driven design is the process of designing classes based on some pre-well-defined responsibilities ("pre" because you have to plan out the responsibilities beforehand); responsibilities that, for instance, is determined using the CRC cards method. Would you agree? – Sebastian Nielsen Jan 5 '20 at 11:58
  • 1
    You can do RDD without CRC card: CRC is just a tool to facilitate RDD. But yes, the idea is to determine the responsibility early. A typical example is the MVC design, where each component gets a clear responsibility; or if you look at design patterns, you'll see that class responsibilities and collaboration is also a core element of describing how it works without entering into specific details. Responsibility-driven, is a effective mean to guide separation of concerns. – Christophe Jan 5 '20 at 12:14
  • Question: Since RDD is a process, would it be wrong to say/label some piece of code as of "high RDD"/"low RDD" -- in the same way that we might label code as being of high cohesion or e.g. coupling? – Sebastian Nielsen Jan 7 '20 at 15:56
  • 1
    @SebastianNielsen I think that you can say that some piece follow a RDD, or obey the principles of RDD or have a design that is responsibility driven/oriented. You can relativise with “somewhat”. or they don’t. But I would not quantify a qualitative attribute. It’s also different to compare classes that have a different scope. – Christophe Jan 7 '20 at 16:40
  • 1
    @SebastianNielsen I think my answer is already credible enough with the hyperlinked references it provides. For your convenience, I nevertheless provide you this additional reference to an article of Rebecca Wirfs-Brock who is an early guru of OO thinking and RDD and promoter of a behavioral approach to OO: dl.acm.org/doi/abs/10.1145/74877.74885 - This being said, be aware that requesting resources is out of scope on this site ;-) – Christophe Jan 8 '20 at 20:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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