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. Right click on the resetTime operation and select Create Method > Behavior, then select Opaque Behavior (or Activity).
  4. Right click again on the resetTime operation and open the Alf editor window (select Windows > Alf), if it isn't already open.
  5. Enter the Alf code shown in the figure below.



  6. When the Alf code is correct, click 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. Right click on the increaseTime operation and select Create Method > Behavior, then select Opaque Behavior (or Activity).
  4. Click on the increaseTime operation and, in the Alf editor window, 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