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


  1. Right-click the StopWatch class in the Model Browser and select Create Element > Operation.
  2. Name the new operation resetTime (see the following figure).



  3. While resetTime operation is selected, open the Alf editor window (select Windows > Alf), if it isn't already open, and press Create.
  4. Enter the Alf code shown in the figure below.



  5. When the Alf code is correct, press Save.


To create the increaseTime Operation


  1. Right-click the StopWatch class in the Model Browser and select Create Element > Operation.
  2. Name the new operation increaseTime.
  3. Click on the increaseTime operation and, in the Alf editor window, press Create.

  4. Enter the Alf code shown in the figure below.



  5. When the Alf code is correct, click Save.


Next: Defining the Ready and Running behaviors using Alf