Type Hierarchies

Constraint Modeling Language (CML) supports inheritance and overriding, which allow you to create hierarchies between types. By establishing these hierarchies, constraint models become more modular and efficient.

  • Inheritance: This mechanism enables a specialized child type to automatically share common variables (attributes) and relationships defined in its parent type. By inheriting from a base type, child types don’t need to redefine shared properties, which ensures consistency across the model.
  • Overriding: While child types inherit the structure of the parent, they can override or specialize those properties. For example, a parent type might define a variable with a broad range of possible values, while a child type overrides that variable with a fixed value specific to that individual product.
  • Simple Product Extension: A BaseProduct might define an id and name. A PhysicalProduct can then inherit from BaseProduct to gain those fields while adding its own unique characteristics, such as weight or color.

  • Multi-Level Nesting: Hierarchies can extend through multiple layers. For instance, a Room type can be the parent to a Bedroom type, and a MasterBedroom can further inherit from the Bedroom type, carrying all properties down the chain.

  • Abstract Base Models: In complex configurations such as a GeneratorSet, a parent type such as GeneralModel defines the necessary attributes (such as powerKW and dB), while specific child types such as GeneralModel900 or GeneralModel1200 inherit those attributes and override them with their specific ratings.

    To define a relationship with an abstract type, associate the abstract type with at least one product. If an abstract type declares a relationship when it isn’t associated with a product, it causes a missing association error. Define relationships on concrete child types instead.

By establishing these hierarchies, constraint models become more modular and efficient. You can create header-level declarations and base types to serve as a foundation for the entire model, allowing you to reference reusable components multiple times rather than writing redundant code for every product variation. This structural organization allows the constraint engine to effectively enforce business logic and validate configurations across all related types.

In this pattern, a specialized type inherits from a broader base type. In the provided generator set model, the GeneratorSet type inherits from LineItem, gaining any properties defined at the line-item level while adding its own specific configuration fields like requiredKW and Voltage.

CML supports hierarchies with multiple layers of depth. In this example, properties flow from the top-level LineItem down to the GeneratorSet, and finally to a highly specialized EmergencyGenerator. Each level inherits all attributes from the levels above it.

This pattern uses an abstract type as a structural blueprint. Specific components (the “General Models”) inherit from this blueprint and override its generic attributes with fixed, real-world ratings.