Semantics Described using UML
This chapter describes the semantics of the OCL using the UML itself to
describe the semantic domain and the mapping between semantic domain
and abstract syntax. It explains the semantics of OCL in a manner based
on the report Unification of Static and Dynamic Semantics for UML
[Kleppe2001], which in its turn is based on the MML report [Clark2000].
The main difference between Appendix A ("Semantics"), which describes
the semantics in a formal manner, and this chapter is that this chapter
defines a semantics for the ocl message expression.
Introduction
In Section 8.3 ("The
Expressions Package") an OCL expression is defined as: "an
expression that can be evaluated in a given environment", and in
Section 8.2 ("The Types Package")
it is stated that an "evaluation of the expression yields a value". The
`meaning' (semantics) of an OCL expression, therefore, can be defined
as the value yielded by its evaluation in a given environment.
In order to specify the semantics of OCL expressions we need to define
two things: (1) the set of possible values that evaluations of
expressions may yield, and (2) evaluations and their environment. The
set of possible values is called the semantic domain. The set
of evaluations together with their associations with the concepts from
the abstract syntax represent the mapping from OCL expressions to
values from the semantic domain. Together the semantic domain and the
evaluations with their environment will be called domain in
this chapter.
The semantic domain is described in the form of a UML package,
containing a UML class diagram, classes, associations, and attributes.
The real semantic domain is the (infinite) set of instances that can be
created according to this class diagram. To represent the evaluation of
the OCL expressions in the semantic domain a second UML package is
used. In it, a set of so-called evaluation classes is defined
(in short eval). Each evaluation class is associated with a
value (its result value), and a name space environment that binds names
to values. Note that the UML model comprising both packages, resides on
layer 1 of the OMG 4-layered architecture, while the abstract syntax
defined in Chapter 8 ("Abstract Syntax"), resides on layer 2.
The semantics of an OCL expression is given by association: each value
defined in the semantic domain is associated with a type defined in the
abstract syntax, each evaluation is associated with an expression from
the abstract syntax. The value yielded by an OCL expression in a given
environment, its `meaning', is the result value of its evaluation
within a certain name space environment. The semantics are also
described in the form of a UML package called "AS-Domain-Mapping". Note
that this package links the domain on layer 1 of the OMG 4-layered
architecture with the abstract syntax on layer 2. The AS-Domain-Mapping
package itself can not be positioned in one of the layers of the OMG
4-layered architecture. Note also that this package contains
associations only, no new classes are defined.
Figure 14 shows how the packages defined in this chapter relate
to each other, and to the packages from the abstract syntax. It shows
the following packages:
-
The Domain package describes the values and evaluations. It is
subdivided into two subpackages:
-
The Values package describes the semantic domain. It shows the
values OCL expressions may yield as result.
-
The Evaluations package describes the evaluations of OCL
expressions. It contains the rules that determine the result value for
a given expression.
-
The AS-Domain-Mapping package describes the associations of the
values and evaluations with elements from the abstract syntax. It is
subdivided into two subpackages:

- The Type-Value package contains the associations between
the instances in the semantics domain and the types in the abstract
syntax.
- The Expression-Evaluation package contains the
associations between the evaluation classes and the expressions in the
abstract syntax.