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

User Manual    [Previous]   [Next]   

Composing State Machines

State machines can be built from parts. Elements of state machines can be added in several ways:

  • By repeating the state machine definition in the same class, adding more detail. In the example below, the state machine sm has part of its definition starting at line 2, and part of its definition starting at line 26.

  • By using standalone transitions. Line 20 shows that outside the context of any state, a transition can be defined. Just add the origin state before the arrow. This one indicates that when e3 occurs, if in state b, then go to state a. This notation can be used to help separate concerns, and place focus on a particular transition. Another example of this is at line 31, where event e5 can cause a transition from state bsub1 to state a. Note that line 34 shows another way of indicating a standalone transition, by adding more detail to state a (that had already beed defined starting at line 3).

  • By using mixins where a more detail to a class (and its contained state machine) is added. Starting at line 26, there is a new definition adding more detail to class X, which in turn adds more detail to state machine sm starting at line 29.

  • By using mixsets: Mixsets are like mixins but can be either excluded or included in the system. To include a mixset,add a use statement (as i line 49) or command line option. An example starts at line 39, where yet more detail is added to class X and its state machine sm. This is activated with the use statement at line 49.

Illustration of various ways of adding details to a state machine

class X {
  sm {
    a {
      // Ordinary transition
      e1-> bsub1;
    }
    b {
      bsub1 {
        // transition in substate
        e2 -> bsub2;
      }
      bsub2 {}
    }
    // Standalone transition
    // at to level
    e3 b -> a;
    
    // Standalone transition
    // between substate
    e4 bsub2 -> bsub1;
  }
}

// Mixin for class that mixes in
// more details into the state machine
class X {
  // Supplemental detail for same
  // state machine
  sm {
    // Standalone transition
    e5 bsub1 -> a;
    
    // Another way of adding a transition
    a {e6 -> bsub2;}
  }
}

// Mixset to optionally add more detail
mixset extra class X {
  sm {
    // Adding a new state
    c {}
    // Adding a transition
    e7 b -> c;
  }
}

// Activating the above mixset
use extra;
      

Load the above code into UmpleOnline

 

Syntax


// State machine elements in Umple. See user manual page: BasicStateMachines
stateMachineDefinition : statemachine [=queued]? [=pooled]? [name] { [[state]]* }

state : [=final]? [stateName] { [[stateInternal]]* }

// A transition guard can come before or after the arrow
// The order of guard and event definition can also be interchanged
transition :
  ( [[eventDefinition]] [[guard]]
    | [[guard]] [[eventDefinition]]
    | [=unspecified]? [[guard]]
    | [[eventDefinition]]
  )?
  ( [[action]] ->
    | -> [[action]]
    | ->
  ) [stateName] ;

//Issue148
standAloneTransition :
  ( [[eventDefinition]] [[guard]]
    | [[guard]] [[eventDefinition]]
    | [=unspecified]? [[guard]]
    | [[eventDefinition]]
  )? [~fromState]
  ( [[action]] ->
    | -> [[action]]
    | ->
  ) [~toState] ;