An aggregation is an association, in which one class belongs to a collection. For instance, an order can have a collection of order details.
A composition is a strong association in which the part can belong to only one whole - the part cannot exist without the whole.
Naming class aggregations or compositions as shown in figure Class Aggregations and Compositions is optional. For each aggregation or composition there are two association ends . At least one of these association ends must have a name, because in action scripts, you navigate through aggregations or compositions by using the association end names. They play a similar role as attribute names. Actually, all aggregations or compositions having an association end name can be represented as an attribute as well.

Figure: Class Aggregations and Compositions

Classes that are linked together via aggregations or compositions are not instantiated automatically when their relationship partner classes are instantiated. They need to be instantiated as well (refer to figure Navigating Through Aggregations and Compositions).
For instance, aggregated classes need to be instantiated first. The resulting objects may be assigned to the attribute, which have the same name as the association end name of the aggregated class. In action node Create Aggregated Object, an instance of class PartTwo is assigned to the attribute composition1 of object aggregatedObject. composition1 has been defined as association end name in the class diagram in figure Class Aggregations and Compositions.

Figure: Navigating Through Aggregations and Compositions

The action script of action node Create Aggregated Object shows an example of how to navigate through aggregations or compositions:

set aggregatedObject.aggregation1.part1 = "My Value";

The attribute part1 is referenced via the attribute aggregation1, which is the name of the aggregation end name. The aggregation end name is used as attribute here and actually stores a reference to the object partOne, which was created in action node Create Part Objects (see set aggregatedObject.aggregation1 = partOne;). The object partOne has an attribute part1, to which the value My Value is assigned (compare class diagram in figure Class Aggregations and Compositions).

  • No labels