| |
The Untitled1 class creates instances of three classes which implement the List interface. Figure 2 shows what class Untitled1 looks like in a UML diagram. Figure 3, 4 and 5 show that ArrayList, Vector and LinkedList all implement the List interface. Figure 6 shows a UML view of the List interface.
Figure 2: In this UML dialog a solid line ending in an open arrow shows that Untitled1 contains instances of the ArrayList, LinkedList and Vector classes. Compare with the dotted line and closed arrow symbol shown in Figure 3.
Figure 3. ArrayList implements the List interface.
Figure 4. LinkedList implements the List interface.
Figure 5. Vector implements the List interface.
Figure 6. The List interface as seen in a UML diagram. The plus signs represent public methods. Compare with Figure 2, where JBuilder standard icons from the Structure Pane are displayed. JBuilder allows displaying UML in either mode.
The ArrayList, LinkedList and Vector classes all conform to the contract established by the List interface. Unlike the Runnable interface, the List interface declares multiple methods. By conforming to this contract, the ArrayList, LinkedList and Vector classes all promise to implement the methods of the List interface such as add(), get(), indexOf() and isEmpty(). In other words, these classes all display the behavior associated with the List interface. Is this sense, they all belong to the same family.
Most experienced drivers can pilot any reasonably sized car. They can do this because the interface for a car is the same in most vehicles, whether that car is a Honda, a Ford or a BMW. In the same way, most developers who know the List interface can use the ArrayList, LinkedList and Vector classes. Just as all cars have a steering wheel and a transmission, so do all classes that implement the List interface have methods such as add(), get() and indexOf(). In this sense, all these classes behave in the same manner. |
|