Home

 

Relationships

Relationships are used to document the semantic ties that exist between model elements. Four commonly used categories of UML relationships are listed here:

Dependency relationships-This type of relationship is used to indicate that changes to a specific model element can affect another model element. For example consider a Bank class which depends on an Account class. An operation that can be called on an object of the Bank class might take as a parameter a reference to an object of the Account class. The Account object has been created elsewhere but the Bank object uses it and therefore depends on it. After the Account object has been used, the Bank object does not retain its reference to it. A dependency relationship therefore exists between the Account class and the Bank class.

Association relationships-This type of relationship indicates that instances of a specific model element are connected to instances of another model element. For example, a Customer class might have an association with an Account class. When an object of the Customer class obtains a reference to an object of the Account class, it retains it and can interact with the Account object whenever required. If the classes were to be implemented in Java, then typically the Customer class would include an instance variable to hold the reference to an Account object.

There are several different types of association relationship that can be used depending on how tightly connected the modelling elements are. Consider, for example, a relationship between a Car and Engine class. In this case the association is stronger than in the previous Customer and Account example. One of the stronger types of association such as aggregation or even composition might therefore be used in the model. In the case of composition, the connection between the classes is so strong that the lifetimes of the objects are bound together. The object of one class never exists without an object of the other, and when one is deleted so is the other.

Generalization relationships-This type of relationship is used to indicate that a specific model element is a generalization or specialization of another model element. Generalization relationships are used to show inheritance between model element. If Java is used to implement a UML class element and that element has a generalization relationship with another class in a model, the Java extends keyword would be used in the source code to establish this relationship. For example, an Account class might be a generalization of a SavingsAccount class. Another way to say this is that the SavingsAccount is a specialization of the Account class, or that the SavingsAccount class inherits from the Account class.

Realization relationships-This type of relationship is used to indicate that a specific model element provides a specification that another model element implements. Realization relationships are typically used between an interface and the class which implements it. The interface defines operations and the class implements the operations by providing the method behind each operation. In Java this maps to the implements keyword. For example, consider a Command interface and a DepositCommand class. A realization relationship would exist in the model between the DepositCommand class and the Command interface. In other words, this means that the DepositCommand class implements the Command interface.
ibm.com/redbooks