This tutorial you will construct a state machine model for a simple stopwatch that increments by 1 every second. This model is a version of the stopwatch model used in the tutorial for Cameo Simulation Toolkit (CST). However, unlike in the CST toolkit, Behaviors will be defined using Alf, rather than Activity diagrams.

The stopwatch structure

The structure of the stopwatch model in this tutorial is very simple. It only contains a time property, which is typed as Integer. The time property records the elapsed time once the stopwatch receives a starting Signal. Therefore, the structure of the stopwatch system contains a StopWatch class that has the time property.

The stopwatch behavior

The tutorial uses a State Machine diagram to describe the main behavior of the stopwatch. The State Machine consists of four States:

  1. ready – The State in which the stopwatch is ready to start.
  2. running – The State that the stopwatch enters once it receives a Start signal. The stopwatch runs and the timer starts. The stopwatch is triggered by a Time Event to increment the time value by 1 each second.
  3. paused – The State in which the stopwatch is paused and waiting for the user to restart it.
  4. stopped – The State in which the stopwatch stops running.

The tutorial consists of the following steps: