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

User Manual    [Previous]   [Next]   

Final States

In Umple, there are two ways to define final states.

The first way is to use the "Final" keyword (with a capital F) as the destination of a transition. This automatically defines a final state for the top-level state machine. Once the state machine is in this state, it is considered to be complete, and it is terminated. The "Final" keyword can be used as shown in the example below. Note, if a user defines a state named "Final", error E074 User Defined State Cannot be Named Final will be thrown.

The second way is to use the "final" keyword (lower case) before a state name to tag a state as final. Using this keyword allows users to define multiple final states as shown in the second example below. In the case of concurrent regions (indicated using the || in the example), all state machines within the same concurrent region must be in their final states before the enclosing region is considered to be complete. In the case of non-concurrent state machines, as soon as a final state is entered, the state machine is considered to be complete.

Example with the "Final" keyword

// Using the keyword "Final" automatically defines the 
// final state for the top-level state machine "sm"

class X {
  sm {
    s1 {
      goToS2 -> s2;
    }
    s2 {
      goToFinal -> Final;
    }
  }
}
      

Load the above code into UmpleOnline

 

Example of concurrent state machines with "final" states

// "s1" is an orthogonal region, and it is
// considered to be complete when all of the
// concurrent state machines are in their final
// states (i.e. s2 is in state "s4", s5 is in
// state "s7", and s8 is in state "s10")

class X {
  sm {
    s1 {
      s2 {
        s3 {
         goToS4 -> s4;
        }
        final s4 { }
      }
      ||
      s5 { 
        s6 {
          goToS7 -> s7;
        }
        final s7 { }
      }
      ||
      s8 {
        s9 {
          goToS10 -> s10;
        }
        final s10 { }
      }
    }
  }
}
      

Load the above code into UmpleOnline

 

Example of non-concurrent state machines with "final" states

// "sm" will be considered as complete when
// it is in either state "s3" or "s5"

class X {
  sm {
    s1 {
      s2 {
        goToS3 -> s3;
        goToS4 -> s4;
      }
      final s3 { }
    }
    s4 {
      goToS5 -> s5;
      final s5 { }
    }
  }
}
      

Load the above code into UmpleOnline