list of dots Digital Research Alliance of Canada logo  NSERC logo  University of Ottawa logo / UniversitĂ© d'Ottawa

User Manual    [Previous]   [Next]   

Extending a State

This operator is used to assign a state machine to a specific state inside another state machine, hence turning that state into a composite state. The syntax used for this operator is as follows:

srcStateMachineName as desStateMachineName.stateName.....stateName

This operator involves two state machines. The srcStateMachineName is found in the trait, and the desStateMachineName is found in the client. The state in the client can be simle or composite. This operator provides a practical mechanism to incrementally compose a state machine from various parts. For example, simple 'on/off' pairs of states with events to toggle between are fairly common and can be injected easily into destination states using this operator. If a composited state is extended with this operator, it will trigger our composition algorithm which. Furthermore, the operator can be used to bring more than one state machine inside a state.

In example 9, class C1 has state machine sm with two states s1 and s2. Trait T1 has state machine sm1. Class C1 needs to have state machine sm1 activated when it is in state s2. Class C1 achieves this by specifying the source state machine and destination state when it uses trait T1 (line 15).

Example

/*
  Example 9: showing how the operator
  "Extending a state by adding a state machine
  to it" works.

  To see different diagram views in UmpleOnline:
    Use control-g for auto-layout as a class diagram
    Use control-r to switch between trait view and
       plain classes resulting from applying traits
    Use control-m to show/hide methods
    Use control-s to show the resulting state diagram
*/
trait T1{
  sm1{    
    m1{
      t2-> m2;
    }
    m2{
      t1-> m1;
    }
  }
}
class C1{
  isA T1<sm1 as sm.s2>;
  sm{
    s1{
      e2-> s2; 
    }
    s2{
      e1-> s1;
    }
  }
}
// @@@skipcppcompile

      

Load the above code into UmpleOnline