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 |
|