16.18. Template Classes and Interfaces
Many languages (Java, C++, …) support templatized types , also known (with shades of variant meanings) as templates, parameterized types , and generics .[7] They are most commonly used for the element type of collection classes, such as the elements of lists and maps. For example, in Java, suppose that a Board software object holds a List (an interface for a kind of collection) of many Squares . And, the concrete class that implements the List interface is an ArrayList :
[7] Motivations for template classes include increased type safety and performance.
Notice that the List interface and the ArrayList class (that implements the List interface) are parameterized with the element type Square . How to show template classes and interfaces in the UML? Figure 16.18 illustrates.
public class Board
{
private List<Square> squares = new ArrayList<Square>();
// …
}
Figure 16.18. Templates in the UML.
[View full size image]