20.5. Collection Classes in Code
One-to-many relationships are common. For example, a Sale must maintain visibility to a group of many SalesLineItem instances, as shown in Figure 20.5. In OO programming languages, these relationships are usually implemented with the introduction of a collection object, such as a List or Map , or even a simple array.
Figure 20.5. Adding a collection.
[View full size image]
If an object implements an interface, declare the variable in terms of the interface, not the concrete class.For example, in Figure 20.5 the definition for the lineItems attribute demonstrates this guideline:
private List lineItems = new ArrayList();