MSc-IT Study Material
January 2011 Edition

Computer Science Department, University of Cape Town
| MIT Notes Home | Edition Home |

Relationships between classes

Finding and describing classes is the first stage of class modelling. The next stage is to determine, and show, how classes are related.

In the simplest terms, a relationship between two classes is shown by a line (as it is in an entity relation diagram):

Figure 5.2. A relationship between two classes

A relationship between two classes

In general such a relationship is referred to as a link, association, or a collaboration.

In the diagram above, the classes are shown with horizontal dashes where the operations and attributes normally go; this is an indication that there are some operations and attributes, but they are not shown on this diagram. It is also permissible to show a class simply as a rectangle, but then the reader does not know whether the class has attributes and associations and they are not shown, or if it does not have any at all.

The line connecting the two classes has an arrow to indicate the direction of the association. Objects of class LibraryMember borrow objects of class Book, not the other way around. This is fairly obvious from the context in this example, and the arrow could have been omitted, but if you are working on a system which is less obvious it does well to include the arrows. Note that links should have names, although you will not always want to show the name on the diagram (to reduce clutter). If you cannot assign a sensible name to a link, it is probably not a real link, or the classes at each end are incorrect. Normally a link should be able to have a relatively simple, short name, which will probably be a verb.

The UML is strict about the positions of arrows. It would be incorrect to draw the arrow in the figure above on the line. Arrows on lines have a different meaning altogether.

The links shown above is an example of a named association; it is the most general kind of link. The UML also recognises a number of special-purpose links, which will be described later.