Types of UML Relationships – Dependency, Association, Generalization and Realization
Articles by Bala Paranj
1. Dependency
public class DanceTeam {
public void join(Dancer aDancer) {...}
}
In this example there is a Dependency relationship between the DanceTeam class and the Dancer class. As you can see from the
signature of the method join takes a parameter of type Dancer. As a side note, it is not necessary (dotted line from one class to
another) to show this in the class diagram. It could clutter the class diagram rather than making it clear.
2. Association
public class Book {
private Author author;
....
}
In this example there is an Association relationship between the Book and the Author classes. In the code, the Book class has a
private attribute of type Author. We can navigate from the Book class to the Author class. The direction of navigability is from the Book
to the Author. We can also say that the Book class "knows" about the Author class.
3. Generalization
public class Apple extends Food {
....
}
The generalization shows up as the inheritance in the code. In this example the keyword "extends" is used to implement the concept
of generalization.
4. Realization
public class MySplashWindow implements Runnable {
....
public void run() {...};
}
In a Realization relationship a Class implements a contract defined by an interface. The keyword "implements" is used in the
code. In this example the class MySplashWindow implements the Runnable interface. The runnable interface has the method run()
defined in it.
Let us declare a field dancerList container at the class level that can hold instances of Dancer.
Since the dancerList attribute is a container class that can hold many dancers, it would imply
that there is a one-to-many relationship between the DanceTeam and the Dancer classes.
To be more specific, this is actually an Aggregation relationship.
DanceTeam aggregates Dancer objects. Dancer can live outside the scope of a particular DanceTeam.
Perhaps, she could become member of another DanceTeam.
OOAD skills for the real world projects
Study Guide - Object Oriented Analysis and Design with UML