Associations describe the network of structural relationships that exist between classes, and give birth to links between the objects that are instances of these classes. Links may be viewed as inter-object navigation channels. These channels facilitate moving around within the model and implementing the types of collaboration that correspond to the various scenarios.
By default, associations can be navigated in both directions. In some cases though, only one navigation direction is usable; an arrow pointing in the direction navigation is possible illustrates this. The absence of an arrow implies that the association may be navigated in both directions. In the following example, object instances of A
see object instances of B
, but the object instances of B
cannot see the object instances of A
.
An association that can only be navigated in one direction may be seen as a half-association. This distinction is often implemented at design time, but it can also appear during design, when study of the domain reveals an asymmetry in the communication requirements.
UML defines a pseudo-language to represent paths within class diagrams. This very simple language defines expressions that are used, for example, to specify constraints. The left part of the expression specifies a set of objects. A class name identifies the set of all object instances of the class.
The syntax for the target of the navigation expression can be obtained using the four following rules:
set '.' selector
The selector
corresponds either to the name of an attribute of the objects within the set
, or to a role name attached to a link that relates to the objects of the set
. The target is a set of values or objects, and their number depends on the multiplicity of the set
and of the association.
In the case of an association, the expression returns a collection of objects that contains the number of elements specified by the multiplicity of the role. The expression APerson.Children
refers to all the children of a given person.
set '.' '~' selector
The selector
corresponds to a rolename placed next to the set
. The target is a set of objects obtained by navigation in the direction opposite to the rolename. In the above example, the parents of a child are identified by the expression APerson.~Children
.
set '->' 'select' '(' boolean_expression ')'
The boolean_expression
is built from objects contained within the set
, from links and values accessible by these objects. The target is a set of objects that satisfy the expression, and a subset of the initial set. In the above example, the boolean_expression
APerson.Children [age>=18 years]
refers to all the responsible children of a given person.
set '.' selector '[' qualifier ']'
The selector
indicates an association that partitions the set
based on the qualifier
. The target is a subset of the set
defined by the association.
In the following example, adding qualifiers to the association, which results in reducing the multiplicity, performs a restriction. The general expression APerson.Child[AFirstName]
identifies a given child in an unambiguous way, since each child of the same family has a different first name.
The above expressions are particularly well adapted to the formation of pre- and post-conditions attached to the operations' specifications. In the last example, the operations that create family links must correctly associate parents and their children. This can be expressed by the following constraint.
{APerson = APerson.Child[AFirstName].(Parent[Mother] or Parent[Father])}
Or else, by navigating in the opposite direction:
{APerson = APerson.Child[AFirstName].(~Child[Mother] or ~Child[Father])}
Or, finally, by setting:
{daddy = APerson.Parent[Father]}
And:
{granddad = APerson.(Parent[Father] or Parent[Mother]).Parent[Father]}
Then:
{granddad.Parent[Father] = daddy.Parent[Father].Parent[Father]}
Which is equivalent to saying, as everyone knows, that the daddy of the granddad is the granddad of the daddy!
© 1997 Editions, Eyrolles, Paris, France . All rights reserved.