Skip to main content

Composition References

Composition References create parent-child relationships between ElementClasses.

Compositions:

  • Can be one or two-directional.
  • Create a hierarchy where the owner (parent) contains the target (child).
  • Can target ElementClasses from other Ontologies only if there is no Opposite Reference. If the composition is bidirectional, both ElementClasses need to exist in the same Ontology.
  • Do not require the target ElementClass to have identifiers.
model/references/Script_parameters.xml
<reference name="parameters">
<associationType name="composition"/>
<owner name="Script" ontology="scriptElements"/>
<target name="ScriptParameter" ontology="scriptElements"/>
<cardinality>
<minimum>0</minimum>
<maximum>*</maximum>
</cardinality>
<opposite name="script">
<cardinality>
<minimum>1</minimum>
<maximum>1</maximum>
</cardinality>
</opposite>
</reference>

Composition in action
MyScript.xml
<script>
<parameters>
<scriptParameter>
<name>output</name>
</scriptParameter>
<scriptParameter>
<name>log-level</name>
</scriptParameter>
</parameters>
</script>

Single value composition

A Composition Reference can also have a cardinality of 0..1 or 1..1. In this case there is a one-to-one relation between parent and child.

This can be useful in several cases:

  • Optional extra behaviour: the child encapsulates some concern that is only activated if the child is defined.
  • Reusable behaviour: the same ElementClass is the child in a number of Compositions (without Opposite Reference) and adds some common behaviour.