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
BaseProductmight define anidandname. APhysicalProductcan then inherit fromBaseProductto gain those fields while adding its own unique characteristics, such asweightorcolor. -
Multi-Level Nesting: Hierarchies can extend through multiple layers. For instance, a
Roomtype can be the parent to aBedroomtype, and aMasterBedroomcan further inherit from theBedroomtype, carrying all properties down the chain. -
Abstract Base Models: In complex configurations such as a
GeneratorSet, a parent type such asGeneralModeldefines the necessary attributes (such aspowerKWanddB), while specific child types such asGeneralModel900orGeneralModel1200inherit 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.