Skip to content

Cardinalities of Elements

Previously, our product definition only allowed for representing single instances of a type. For example, we specified a front wheel and rear wheel to represent the two wheels of a standard bicycle, and we could only accommodate one bag on the carrier.

Fixed Cardinalities

We enhance the Carrier definition by adding a cardinality annotation to the type Bag. This update specifies that a carrier can accommodate anywhere from zero to three instances of a Bag.

// Updated definition with cardinalities
structure Carrier {
          Color carrierColor
     0..3 Bag   bags        
}

The specific cardinality of a type is put in front of the type name. For a fixed cardinality you simply give the corresponding count, e.g.,

structure Carrier {
          Color carrierColor
        2 Bag   bags
}

will require exactly two bags in each configuration. If no cardinality is given, then the default cardinality 1 is used (e.g., for definition Color carrierColor).

Static Features of Cardinalities

When defining a cardinality of a feature as illustrated for Bag in the example above, both instances of Bag will hold separate values for capacity and material.

structure Bag { 
    Capacity capacity
    Material material
}

If the keyword static is used for an element, it ensures that any feature of type Bag existing in the product shares the same value of Material.

structure Bag { 
           Capacity capacity
    static Material material
}

The example defines material to be a static feature of structure Bag. That way, all bags share the same value of Material.