Java Reference
In-Depth Information
If a class can carry out that responsibility by itself, do nothing further. But if the class
needs the help of other classes, write the names of these collaborators on the
right-hand side of the card.
To compute the total, the invoice needs to ask each line item about its total price.
Therefore, the LineItem class is a collaborator.
537
538
Figure 5
A CRC Card
This is a good time to look up the index card for the LineItem class. Does it have a
Ȓget total priceȓ method? If not, add one.
How do you know that you are on the right track? For each responsibility, ask
yourself how it can actually be done, using the responsibilities written on the various
cards. Many people find it helpful to group the cards on a table so that the
collaborators are close to each other, and to simulate tasks by moving a token (such as
a coin) from one card to the next to indicate which object is currently active.
Keep in mind that the responsibilities that you list on the CRC card are on a high
level. Sometimes a single responsibility may need two or more Java methods for
carrying it out. Some researchers say that a CRC card should have no more than three
distinct responsibilities.
Search WWH ::




Custom Search