Java Reference
In-Depth Information
After this process of elimination, we are left with four candidates for classes:
Invoice
Address
LineItem
Product
Each of them represents a useful concept, so let's make them all into classes.
The purpose of the program is to print an invoice. However, the Invoice class
won't necessarily know whether to display the output in System.out , in a text
area, or in a file. Therefore, let's relax the task slightly and make the invoice
responsible for formatting the invoice. The result is a string (containing multiple
lines) that can be printed out or displayed. Record that responsibility on a CRC card:
545
546
How does an invoice format itself? It must format the billing address, format all
line items, and then add the amount due. How can the invoice format an address? It
can'tÈŒthat really is the responsibility of the Address class. This leads to a second
CRC card:
Search WWH ::




Custom Search