First, use the Alf project template to create a new project called StopWatch.  Next, define a stopwatch Class and its attributes using a Class diagram.


To create a StopWatch Class (on a Class diagram in a new Package)


  1. Right click Model in the Model Browser and select Create Element > Package. A new Package will be created under the Model node. Name the created Package system (see the following figure).



  2. Click on the system package and create a new Class diagram in the package by clicking the Create Diagram button on the toolbar. The Create Diagram dialog will open (see the following figure). Select Class Diagram.



  3. Name the class diagram System.

    You can also use the context menu of the system package to create a new Class diagram by right-clicking the system package and selecting Create Diagram > Class Diagram.

  4. Use the diagram toolbar of Class Diagram to create a new Class element and name the created Class StopWatch (see the following figure). 


Now add a time attribute to the StopWatch class. Since this attribute represents the elapsed time in seconds, type it as Integer.

To add a time attribute to the StopWatch class


  1. Click the small Create Element button on the StopWatch class and select Property. A new attribute will be created in the StopWatch class.
  2. Name the attribute time and give it type Integer by directly typing that into the attribute compartment of the StopWatch class (see the following figure).


Next:  Creating the StopWatch state machine

Related pages