Skip to main content

Features

Features define the structural relationships between classes. Unlike variables (which hold runtime state), features are resolved during instantiation and eliminated during flattening; they do not exist at runtime.

Feature Kinds​

KindMeaning
containsThe class owns instances of the target type.
refersA cross-reference to instances owned elsewhere.
containerThe reverse of contains; must be paired via opposite.
derived refersA reference whose value is derived from the model structure.
featuresAn abstract feature that subclasses redefine as contains or refers, or fill through subsetters.

contains​

A contains feature declares ownership: each instance of the enclosing class owns its own instance of the target type. A [1] containment is instantiated together with its holder, one instance per holder instance; a containment of any other multiplicity holds only the instances of the features that subset it, so n children are written as n [1] subsetters.

class Pair {
contains a: Counter
contains b: Counter
}

refers​

A refers feature is a cross-reference. It points to an instance that lives elsewhere; there is no ownership.

class Display {
refers source: Counter
}

container​

A container feature is the reverse of a contains feature: the child pointing back to its owning parent. A container must always be paired with the corresponding contains via opposite. A validation rule enforces this pairing.

class Tree {
contains children: Tree[0..*] opposite parent
container parent: Tree[0..1] opposite children
}

derived refers​

A derived refers feature is computed automatically from the model structure. Derived refers features with opposite may be derived from their opposite declaration.

class StateNode {
derived refers inTrans: Transition[0..*] opposite to
derived refers outTrans: Transition[0..*] opposite from
}

features​

The features keyword declares an abstract feature whose kind is left to subclasses. A subclass redefines it as a concrete contains or refers, or fills it through features that subset it: one that is not redefined holds the instances of its subsetters.

abstract class Container {
features payload: any
}
class IntContainer : Container {
redefine contains payload: int
}

Multiplicities​

A feature's multiplicity specifies how many target values are permitted. The multiplicity bracket holds a compile-time expression. The default is [1].

SyntaxMeaning
[1]Exactly one (default)
[0..1]Optional; may be nothing, and a parameter with lower bound 0 may be left out of a call
[0..*]Any number
[n]Exactly n (n is a compile-time expression)
[lb..ub]Between lb and ub
[]No bound given; unlike [0..*], a [] parameter is required and a [] value cannot be nothing

The infinity literal * is allowed in ranges (0..*); a bare [*] is rejected (OXSTS.TYPE_MISMATCH).

opposite​

opposite declares a bidirectional relationship: navigating in one direction automatically populates the other. A validation rule enforces that opposite features point to each other and that container/contains pairs match.

class Tree {
contains children: Tree[0..*] opposite parent
container parent: Tree[0..1] opposite children
}

subsets​

subsets declares that the values of one feature are also included in another, more general feature.

class Wrapper {
contains all: Item[0..*]
contains primary: Item subsets all
}

This is the primary way semantic libraries declaratively add instances to a collection defined in a superclass. A redefinition that names no subsets keeps the superset of the feature it redefines.

redefine and redefines​

redefine overrides an inherited feature of the same name, typically with a more specific type or a more constrained body.

class Counter10Pair : CounterPair {
redefine contains a: Counter10
redefine contains b: Counter10
}

redefines replaces an inherited feature under a new name: the old name no longer resolves on the subclass, and inherited members that use it reach the new feature.

class Counter10Pair : CounterPair {
contains newA: Counter10 redefines a
contains newB: Counter10 redefines b
}

Nested Features​

A feature declaration may include a block of nested feature declarations to redefine inner structure.

contains state: State {
redefine contains entryAction: SetValueAction
}

Feature Binding​

A feature can be bound to a compile-time expression with =. The bound value cannot depend on runtime state.

refers maximum: int = 10

Top-Level (Global) Features​

Top-level features are declared outside any class. They represent shared instances or references that exist at the root of the model. Conceptually, they act as implicit features of the class being instantiated.

KindMeaning
global containmentA top-level owned instance.
global referenceA top-level reference.
global containment globalEvent: Event[1]

Top-level features currently support only the subsets modifier. This restriction may be relaxed in future versions.

global containment sharedEvent: Event subsets sharedEvents