Previous Table of Contents Next


6.8 Association Representations

   Associations constitute a relationship between two classes, and can appear in two forms: either containment relationships or non-containment relationships. Further to this, classes can contain references into associations (see 6.5, “Reference Representations?). This leads to three methods of representing the link between associated class instances.

   Firstly, if one or more of the classes participating in the association contains a reference into the association, then the elements participating in the association can be displayed within the representation of the class containing the reference, as described above in 6.5, “Reference Representations.?

   Secondly, if the association represents a containment relationship, but there are no classes with references to the association, the association contents may be displayed within the representations of the containing class instances. The representation for the contained instance is exactly the same as if it were referenced, except that the name of the association is substituted for the name of the reference. This is shown by the production rules in 6.3, “Class Representations.? The association name is optionally displayed before the contained class instance to allow disambiguation for MOF models that have more than one possible containment association between the container and the contained instance.

   An example of the representation of unreferenced containment associations is presented in Figure 6-11, where CarOwnership is an association between Family and Car, with Car instances being contained by Family instances.

   FamilyPackage “id-001? { Family “The McDonalds? { CarOwnership: Car “755-BDL? { Attribute and reference representations

   } } }

   Figure 6-11 An example of a containment association without references

   [32] AssocInstance := 33: AssocBlock | 36:InfixAssocLink

   [33] AssocBlock :=<AssocName> ‘{‘ 34:AssocContents ‘}’

   [34] AssocContents := ( 35:AssocEnd 35:AssocEnd ) *

   [35] AssocEnd := (<AssocEndName> (’:’ | ‘=’) )? 13:ClassInstanceRef

   The third method of representing association instances involves displaying the link separately to either of the class instances that participate. There are two forms for this: block display of the association, or infix representation of the individual links.

   In the case of block display, a list appears containing references to the class instances participating in the association. The block consists of the name of the association followed by a block (with opening and closing braces) containing the pairs of references to the instances participating in the relationships. Each instance in the pair may optionally be preceded by the name of the role it plays in the association and a colon or equals symbol. Class instance references are displayed in the style specified in 6.3, “Class Representations.? Figure 6-12 shows a block representation of an association ‘sponsorship’ between the Family and Person classes.

   FamilyPackage “id-001? { Family “The Smiths? {

   Attribute and reference representations

   }Person “Namdou Ndiaye? {

   Attribute and reference representations

   }

   sponsorship {

   sponsor: Family “The Smiths?

   sponsored: Person “Namdou Ndiaye?

   Other pairs within the sponsorship association

   } }

   Figure 6-12 An example of the representation for a non-containment association

   [36] InfixAssocLink := 13:ClassInstanceRef <AssocName> 13:ClassInstanceRef

   Infix display consists of references to each of the class instances (in the form appropriate for the participating classes’ identification configuration), separated by the name of the association. It should be noted that the ends of associations are ordered, and the participating class instances must appear in the appropriate order, with the first association end before the association name and the second afterwards. Infix links may be optionally terminated by a semicolon. An example of infix display is shown in Figure 6-13, where Family is the first end of the sponsorship association, and Person is the other end.

   Family “The Smiths? sponsorship Person “Namdou Ndiaye?;

   Figure 6-13 An example of infix display for associations

    As mentioned in 6.5, “Reference Representations? there need only be one representation of any an association link between a pair of class instances. This can be in the form of a reference, or using any of the forms shown above for associations.