6.4 The CRC Card Design Process | 281
A scenario walk-through is intended to explore potential solutions to a problem. We ask a
question such as, “What happens when the user wants to find an address that’s in the book?”
We then answer the question by explaining how each object is involved in accomplishing this
task. In a team setting, the cards are distributed among the team members. When an object
of a class is doing something, its card is held in the air to visually signify that it is active.
For the preceding question, we might pick up the User Interface card and say, “I have a
responsibility to get the person’s name from the user.” That responsibility is written down
on the card. Once the name is input, the User Interface must collaborate with other objects
to look up the name and get the corresponding address. With which objects should it col-
laborate?
We’ve found a hole in our list of classes! The Entry objects should be organized into a Book
object. We quickly write out a Book CRC card. The User Interface card-holder then says, “I’m
going to collaborate with the Book class to get the address.” “Book” is written in the right col-
umn of the User Interface card, which remains in the air. The owner of the Book card holds
it up, saying, “I have a responsibility to find an Entry in the list of Entry objects that I keep,
given a name from User Interface.” That responsibility gets written on the Book card, whose
owner says, “I have to collaborate with each Entry to compare its name with the name sent
to me by the User Interface.” Figure 6.5 shows a team in the middle of a walk-through.
Now comes a decision. What are the responsibilities of Book and Entry for carrying out
the comparison? Should Book get the name from Entry and do the comparison, or should Book
send the name to Entry and receive an answer that indicates whether they are equal? The team
decides that Book should do the comparing, so the Entry card is held in the air, and its owner
says, “I have a responsibility to return a copy of my Name object.”The responsibility is recorded
and the Entry card is lowered.
Class Name: Name Superclass: Subclasses:
Responsibilities Collaborations
Know first None
return String
Know middle None
return String
Know last None
return String
.
.
.
Figure 6.4 A CRC Card with Initial Responsibilities