Class diagrams -Linking

We can link classes together using lines. The lines are known as associations. There are different types of associations and each are represented with a different icon at the end of the line. The image below shows the three different types.

.

Association – This is where classes will communicate with one another using messages or methods. This is the standard link between two classes.

Generalisation – This is inheritance where one class will inherit the attributes and methods form the other class. In the diagram Bar will inherit from Foo (Foo is the superclass and Bar is the subclass).

Aggregation – This is where one class is part of another. In the diagram Bar is part of the Foo class. You can think of it as a “has-a” relationship as in “Foo” has a “Bar”.