Association Role Names - UML

Each end of an association is a role, which has various properties, such as:

  1. name
  2. multiplicity

A role name identifies an end of an association and ideally describes the role played by objects in the association. Figure shows role name examples.

An explicit role name is not required - it is useful when the role of the object is not clear. It usually starts with a lowercase letter. If not explicitly present, assume that the default role name is equal to the related class name, though starting with a lowercase letter.

As covered previously, roles used in DCDs may be interpreted as the basis for attribute names during code generation.

Figure 31.20 Role names

Roles as Concepts versus Roles in Associations

In a domain model, a real - world role especially a human role may be modeled in a number of ways, such as a discrete concept, or expressed as a role in an association. For example, the role of cashier and manager may be expressed in at least the two ways illustrated in Figure.

The first approach may be called "roles in associations"; the second, "roles as concepts." Both approaches have advantages.

Roles in associations are appealing because they are a relatively accurate way to express the notion that the same instance of a person takes on multiple (and dynamically changing) roles in various associations. I, a person, simultaneously or in sequence, may take on the role of writer, object designer, parent, and so on.

On the other hand, roles as concepts provides ease and flexibility in adding unique attributes, associations, and additional semantics. Furthermore, the implementation of roles as separate classes is easier because of limitations of current popular object - oriented programming languages it is not convenient to dynamically mutate an instance of one class into another, or dynamically add behavior and attributes as the role of a person changes.

Figure 31.21 Two ways to model human roles

All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd Protection Status

UML Topics