Information Technology Reference
In-Depth Information
8.5.2.1 Types of Expressions
Expressions can be used in a number of places in a UML model such as:
• To specify the initial value of an attribute or association end.
• To specify the derivation rule for an attribute or association end.
• To specify the body of an operation.
• To indicate an instance in a dynamic diagram.
• To indicate a condition in a dynamic diagram.
• To indicate actual parameter values in a dynamic diagram.
8.5.2.2 Types of Constraints
There are four types of constraints:
• An invariant is a constraint that states a condition that must always be met by
all instances of the class, type, or interface. An invariant is described using an
expression that evaluates to true if the invariant is met. Invariants must be
true all the time.
• A precondition to an operation is a restriction that must be true at the moment
that the operation is going to be executed. The obligations are specified by
postconditions.
• A postcondition to an operation is a restriction that must be true at the
moment that the operation has just ended its execution.
• A guard is a constraint that must be true before a state transition fires.
8.5.2.3 The Context of an OCL Expression
The context definition of an OCL expression specifies the model entity for which
the OCL expression is defined. Usually this is a class, interface, data type, or
component. In terms of the UML standard, this is called a classifier. Sometimes
the model entity is an operation or attribute, and rarely it's an instance. It is always
a specific element of the model, usually defined in a UML diagram. This element
is called the context of the expression (Introduction to OCL 2005 ).
Next to the context, it is important to know the contextual type of an expression.
The contextual type is the type of the context, or of its container. It is important
because OCL expressions are evaluated for a single object, which is always an
instance of the contextual type. To distinguish between the context and the
instance for which the expression is evaluated, the latter is called the contextual
instance. Sometimes it is necessary to refer explicitly to the contextual instance.
The keyword self is used for this purpose.
For example, the contextual type for all expressions in Fig. 8.6 is the class
LoyaltyAccount. The precondition (pre: i [ 0) has context as the operation earn.
Search WWH ::




Custom Search