Visual OCL

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

Language elements with examples

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

1.4 Using methods

Describing the functionality of methods pre and post conditions supply a powerful basis for describing the behavioural constraints of a model. The operation call of the referred method is represented by an arrow downwards to the classifier role, which contains the method. Besides the arrow is written the name of the method and optional a simple condition.
Fig. 1.4 Post condition for the method income in VOCL

The constraint in figure 1.4 describes, that each person has an income of 5000 units of money.

Translated in OCL: context Person::income(d: Date): Integer post: result = 5000

1.5 Assigning Variables

Variables can be assigned to the return values of methods and the values of attributes. Theses variables are useful to generate relations between different attributes and methods.

Fig. 1.5 Using variables

The constraint in figure 1.5 describes, that each person has an income of 1000 times the amount of his age.

Translated in OCL:
context Person::income(d: Date):Integer post:
income = age * 1000

1.6 Value of an attribute before a method call

To describe the result of a method you can use the @pre statement, which describes the attribute value right before the method call happened. This statement is used in the postfix notation with the attribute.

Fig. 1.6 Using values of attributes of the state before the method call

The constraint in figure 1.6 describes, that each person will be one year older at his birthday, then the day before.

Translated in OCL:
context Person::birthdayHappens() post:
age = age@pre + 1


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