Java Reference
In-Depth Information
Similarly, formatting of a line item is the responsibility of the LineItem class.
The format method of the Invoice class calls the format methods of the
Address and LineItem classes. Whenever a method uses another class, you list
that other class as a collaborator. In other words, Address and LineItem are
collaborators of Invoice :
546
547
When formatting the invoice, the invoice also needs to compute the total amount
due. To obtain that amount, it must ask each line item about the total price of the
item.
How does a line item obtain that total? It must ask the product for the unit price,
and then multiply it by the quantity. That is, the Product class must reveal the
unit price, and it is a collaborator of the LineItem class.
Finally, the invoice must be populated with products and quantities, so that it makes
sense to format the result. That too is a responsibility of the Invoice class.
We now have a set of CRC cards that completes the CRC card process.
Search WWH ::




Custom Search