Visual OCL

TU-Berlin | Faculty IV | Institute ISTI | Research group TFS

Language elements with examples

small logo
section: < previous | next >
| |
chapter: << previous | next >>

3. Boolean expressions

VOCL delivers a variety of Boolean expressions including and, or, implies, xor and not. A constraint with a Boolean expression as the outer most container will be fulfilled, if the evaluation of this Boolean expression has the result true.

3.1 The Boolean expressions "implies", "or" and "xor"

A frame surrounds each Boolean expression of the kind implies, or and xor. This frame has two parts in the body containing the two arguments. Each part defines a condition, which may hold or not. Implies is not symmetric and therefore decides between upper and lower, respectively left and right side. The assumption is placed in the upper or left side and the conclusion in the other part. On the dividing line between these parts is placed the label implies.

The example in figure 3.1 describes, that persons in a marriage have to be at least 18 years old. The identity of both classifier roles is defined by the same name "self".

The corresponding OCL text is:
context Person inv: self.isMarried = true implies self.age >= 18
Fig. 3.1 A constraint with an implies expression
Or and xor expressions include there arguments horizontal or vertical like implies, but both sides have the equal result in the entire evaluation. As before the dividing line is labelled by the corresponding expression type "or", respectively "xor".

The example in figure 3.2 describes, that the spouse of a person has to be at least 18 years old.

The corresponding OCL text is:

context Person inv: self.isMarried = true implies
[(self.wife.age > = 18) or (self.husband.age >= 18)]

Fig. 3.2 A navigation starting at an association class

  section: < previous | next >
| |
chapter: << previous | next >>
©2005 TFS