When the StopWatch State Machine enters the ready State, the elapsed time defined by the attribute time: Integer should be reset to zero. In addition, the elapsed time should increment by 1 every second while the StopWatch is in the running state. You can define this functionality using Alf in two Operations on the StopWatch Class: resetTime and increaseTime. These operations will later be called from the entry Behaviors of the appropriate states in the StopWatch State Machine.
To create the resetTime Operation
- Right-click the StopWatch class in the Model Browser and select Create Element > Operation.
- Name the new operation resetTime (see the following figure).
- Right click on the resetTime operation and select Create Method > Behavior, then select Opaque Behavior (or Activity).
- Right click again on the resetTime operation and open the Alf editor window (select Windows > Alf), if it isn't already open.
Enter the Alf code shown in the figure below.
- When the Alf code is correct, click Save.
To create the increaseTime Operation
- Right-click the StopWatch class in the Model Browser and select Create Element > Operation.
- Name the new operation increaseTime.
- Right click on the increaseTime operation and select Create Method > Behavior, then select Opaque Behavior (or Activity).
Click on the increaseTime operation and, in the Alf editor window, enter the Alf code shown in the figure below.
- When the Alf code is correct, click Save.
Related pages