Commonality
Part I
We will model a domain of small regional train stations, restricting our attention to track layouts.
Let’s start with commonalities among the different train stations. Each regional station has some main tracks, and some incoming and outgoing tracks, connecting it to the main line system.
A Clafer model is built predominantly from ‘clafers’ (which assume the roles of classes, objects, features, and associations). We write ‘Clafer’ for the language and ‘clafer’ referring to these building entities.
Every line declares a new
clafer, which represents a concept or a property. The clafers are nested using indentation (main_tracksis a child clafer ofRegionalStationConf, and so aretracks_inandtracks_out).Each clafer is followed by a ‘clafer cardinality’ constraint, which restricts the allowed number of its instances: in general, the cardinality is an interval
n..m, wheremcan be*to indicate unboundedness.In general clafer constraints are interpreted in the instance of the context (parent clafer), so the restriction that there must be exactly one instance of main tracks, holds for each instance of
RegionalStationConfseparately.Convenience notation:
m..msimplifies tom(so1..1simplifies to1),0..1simplifies to?- and
0..*to*
For clafers that are not parts of groups (see about groups later), the default cardinality constraint is
1and can be omitted for brevity. Seetracks_out; in fact all subclafers ofRegionalStationConfhave the same cardinality constraint, just written using alternative notations.A clafer instance can exist only when its parent clafer’s instance exists (e.g., instance of
main_trackscannot exist without an instance ofRegionalStationConf).Clafers with cardinality
1..1(or equivalently1) are called ‘mandatory’ and are used typically to represent commonality.abstractis a keyword indicating that we are introducing a type without any instances (yet). The type can be instantiated either by omittingabstractor as follows:
What are the model instances? In our case, we can interpret our
modelas a description of variability across all small train stations, so different configurations of stations will be instances. Since all clafers in our model are mandatory, there is only a single instance of our model (i.e., there is actually no variability yet). This one configuration has one instance ofmain_tracks, one oftracks_inand one oftracks_out.Let’s use the tool
ClaferIDEto generate the instance.
- Task 1: Press the button to open the model from
this page in the IDE and press the button
Runin theInstance Generatorwindow. Then press the buttonNextto generate another instance and see what happens.
Close the IDE and move to the page
Variability.
