An association is a relationship between instances of two classes. There is an association between two classes, if an instance of one class must know about the other in order to perform its work.

Naming class associations as shown in figure Class Associations is optional. For each association there are two association ends . At least one of these association ends must have a name, because in action scripts, you navigate through associations by using association end names. They play a similar role as attribute names. Actually, all associations having an association end name can be represented as an attribute as well.

Association ends wanting to navigate to in action script must be Navigable. That means, the property Navigable of the association end must be true (default value).

Figure: Class Associations

Associated classes are not instantiated automatically when their association partner classes are instantiated. They need to be instantiated as well (refer to figure Navigating Through Associations).
In the first step, the object of the associated class has to be created (see action node Create Associated Object). This object can then be used in the second step, where the SimpleClass is instantiated (see action node Create Simple Object with Associations).

Figure: Navigating Through Associations

The association association2 (see figure Class Associations) is never used in the activity diagram shown above. Therefore, the object associatedObject will have no association to an object of type AssociatedClass2 and hence no attribute association2. The action script of action node Create Simple Object with Associations shows an example of how to navigate through associations in order to access attributes of associated objects. This is done by referencing the target through a series of <object>.<associationEnd/attribute> statements. For example, simpleObject.association1.string1 allows you to access the attribute string1 of an object, whose reference is stored in the attribute association1. association1 is the name of the association end and is used as attribute of object simpleObject. The other end of the association points to the object's class SimpleClass.

  • No labels