The CRC card method is informal on purpose, so that you can be creative and
discover classes and their properties. Once you find that you have settled on a good
set of classes, you will want to know how they are related to each other. Can you find
classes with common properties, so that some responsibilities can be taken care of by
a common superclass? Can you organize classes into clusters that are independent of
each other? Finding class relationships and documenting them with diagrams is the
topic of the next section.
S ELF C HECK
Suppose the invoice is to be saved to a file. Name a likely collaborator.
Looking at the invoice in Figure 4 , what is a likely responsibility of the
What do you do if a CRC card has ten responsibilities?
12.3 Relationships Between Classes
When designing a program, it is useful to document the relationships between classes.
This helps you in a number of ways. For example, if you find classes with common
behavior, you can save effort by placing the common behavior into a superclass. If
you know that some classes are not related to each other, you can assign different
programmers to implement each of them, without worrying that one of them has to
wait for the other.
You have seen the inheritance relationship between classes many times in this topic.
Inheritance is a very important relationship, but, as it turns out, it is not the only
useful relationship, and it can be overused.
Inheritance is a relationship between a more general class (the superclass) and a more
specialized class (the subclass). This relationship is often described as the is-a
relationship. Every truck is a vehicle. Every savings account is a bank account. Every
circle is an ellipse (with equal width and height).
Inheritance (the is-a relationship) is sometimes inappropriately used when the
has-a relationship would be more appropriate.