2.5.1. UML Relationships

[ fromfile: introuml.xml id: umlrelationships ]

UML is especially good at describing relationships between classes. Jumping ahead a bit to Example 2.22, we will describe an important relationship in UML. In that example we introduce a Point class to represent a geometric point on the screen, and a Square class to represent a geometric shape on the screen. Point has two int data members and Square has two Point data members. The two Point data members, because they are class objects, are regarded as subobjects of Square. The Square object is regarded as the parent of its Point subobjects; when a Square object is destroyed so are its subobjects. That makes the subobjects components of the parent object, and the relationship is called composition. In Figure 2.2, the filled-in diamonds indicate that the instances of that class are composed (at least partially) of instance(s) of the class on the other end of the relationship connector.

Figure 2.2.  Composition

Composition