Chapter 10. Predefined Elements
KerML comes with a set of libraries that include predefined classifiers and features, such as Anything, Occurrence, Object and Performance.
10.1. The Indexical Variables self, that and this
In a nested declaration, the special variable self always refers to the instances of the innermost nested element, which, in the example below, would be the evaluations of the constraint. For a feature nested in a containing element, the variable that refers to the instances of the containing element. Therefore, in the following example, the variable that refers to the instances of NegativeInteger such that the constraint requires all of them to be smaller than 0:
attribute def NegativeInteger specializes Integer { assert constraint { that < 0 } }
For a behavioral feature (e.g., an action or constraint) directly or indirectly composed into a structural model, the variable this refers to the instances (items or parts) of the structural context for the behavior [as explained by Ed Seidewitz in a post on the Google Groups forum SysML v2 Release].
However, the variable this may not be aware of the features of its direct type and therefore should be casted to this type if needed, as in the following example:
part def Car { // <--- "this" attribute velocity : Integer; action drive { // <--- "that" assert constraint { // <--- "self" (this as Car).velocity < 100 } } }
The variable self is a feature that relates everything to itself. It is also the value of the nested that feature of all other things featured by this thing, as implied by declaring that self chains things.that.
// Kernel Base Libraray fragment abstract classifier Anything { feature self : Anything subsets things chains things.that; abstract feature things[1..*] : Anything nonunique { feature that : Anything } }
10.2. Occurrences
The predefined class Occurrence is specialized by Object and Performance, corresponding to the specialization of Class (OccurrenceType) by Structure (ObjectType) and Behavior.
Time slices are portions of occurrences that might have feature values and links to other things peculiar to their smaller period of time. The snapshots of occurrences are time slices that take no time. The earliest snapshot of an occurrence is its startShot, the latest is its endShot. All the others happen during its middleTimeSlice. Occurrences with a startShot the same as their endShot take no time and have no middleTimeSlice.
Occurrences are always portions of themselves. An occurrence that is only a portion of itself (a maximal portion) is an instance of the library class Life.
Other important features of Occurrence are:
- snapshotOf[0..*]
- The occurrences of which this occurrence is a snapshot.
- timeSliceOf[1..*]
- The occurrences of which this one is a time slice, including this one.
- predecessors[0..*]
- The occurrences that end earlier than this one starts.
- successors[0..*]
- The occurrences that start later than this one ends.
- innerSpaceDimension
- The number of variables needed to identify space points in this occurrence, from 0 to 3, without regard to higher dimensional spaces it might be embedded in. For example, the innerSpaceDimension of a curve is 1, even if it twists in three dimensions.
- outerSpaceDimension
- For an occurrence of innerSpaceDimension 1 or 2, the number of variables needed to identify their space points in higher dimensional spaces they might be embedded in, from the innerSpaceDimension to 3. For example , an outerSpaceDimension 3 for a curve indicates it twists in three dimensions. An outerSpaceDimension equal to innerSpaceDimension indicates the occurrence is spatially straight (innerSpaceDimension 1 embedded in 2 or 3 dimensions) or flat (innerSpaceDimension 2 embedded in 3 dimensions).
- spaceSlices[1..*]
- All portions of this occurrence that extend for exactly the same time and some or all the space, relative to spatial location of this occurrence. This means every occurrence is a spaceSlice of itself.
- spaceShots[1..*]
- All space slices of this occurrence that are of a lower innerSpaceDimension than it.
- localClock
- A local clock to be used as the corresponding time reference for this occurrence and, by default, all suboccurrences. By default this is the singleton Clocks::universalClock.