Visual OCL

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

Language elements with examples

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

4. Let expressions

There are two types of let expressions. The first one delivers the assignment to a variable in a definition constraint. This variable is then useable in all constraints regarding to the class model. The second variant of "let" defines a variable that will be used only in the same constraint. Therefore the definition is in the "let" part and the use in the "in" part.

4.1 The "let" expression for definitions

Around the expression, which shall be assigned to a variable, is placed a frame with the label let on top. The variable itself has the position top left inside this frame and is declared with its type. A let expression may have its own condition part on the bottom of the frame.

The example in figure 4.1 defines a variable income that contains the sum of all salaries to a given person.

The corresponding OCL text is:
context Person def:
let income : Integer = self.job.salary->sum()
Fig. 4.1 A constraint with a let expression

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