Visual OCL

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

User Guide for the Eclipse VOCL-Plugin
goup 1

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

4.4 Let-Expressions

Let-Expressions can be used to simplify diagrams. They consist of two parts, a let-part, where a definition of a variable can be made, and an in-part, where the variable then can be used (e.g. in conditions), and do not have to be redefined. This brings advantages when having the same expression several times in nested Boolean or IfThenElse Expressions.

a) Creating a Let-Expressions

  1. Select the Let Expression-Button from among the Container items. Then click inside the constraint-figure, whereupon a dialog appears (see fig. 4.4.1).
  2. Inside this dialog, a variable has to be specified. Name it for example profit and set the type to Integer.
  3. As known from Boolean Expressions, the orientation of the both parts (containers) can be set to either vertical or horizontal. Select as you prefer.
  4. Click the Enter-Button, to insert the let-expression to the constraint. The resulting diagram is displayed in fig. 4.4.2.


Fig. 4.4.1 - Dialog for creation of Let-Expression


Fig. 4.4.2 - Dialog for creation of Let-Expression

b) Example Let-Expression

In order to help understanding the usage of the Let-Expressions, an example is provided now. Have a look at fig. 4.4.3. There is a Let-Expression, which defines a variable called profit, and binds it to the result of the method getProfit. This variable is then used inside the in-part, inside the if-container, where a condition is made upon this variable. The then and else parts do not make use of profit, but they could, if there is need of doing so. The resulting OCL-String is displayed in fig. 4.4.4.


Fig. 4.4.3 - Let-Expression example


Fig. 4.4.4 - OCL-String of the Let-Expression example

 

 


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