Java Reference
In-Depth Information
547
548
12.4.3 UML Diagrams
The dependency relationships come from the collaboration column on the CRC
cards. Each class depends on the classes with which it collaborates. In our example,
the
Invoice
class collaborates with the
Address
,
LineItem
, and
Product
classes. The
LineItem
class collaborates with the
Product
class.
Now ask yourself which of these dependencies are actually aggregations. How does
an invoice know about the address, line item, and product objects with which it
collaborates? An invoice object must hold references to the address and the line
items when it formats the invoice. But an invoice object need not hold a reference
to a product object when adding a product. The product is turned into a line item,
and then it is the item's responsibility to hold a reference to it.
Therefore, the
Invoice
class aggregates the
Address
and
LineItem
classes.
The
LineItem
class aggregates the
Product
class. However, there is no has-a