Skip to content

Final State

Mikołaj Milewski edited this page Apr 1, 2025 · 3 revisions

Overview

Final State represents stable configuration of State Machine. There can be exactly one Final State per Region (if Final State is a substate of Composite State or Orthogonal State) or exactly one per State Machine (if Final State is defined on State Machine's main level).

Final State can't have any outgoing Transitions and, when reached, cannot be exited explicitly. It can be exited only implicitly when parent State is exited.

Final State can't define any OnEntry / OnExit logic.

Outcome of reaching Final State differs depending on its owner:

  • Composite States and Orthogonal States are finalized when Final States in all their Regions are reached,
  • State Machine Behavior is finalized when Final State that is a direct child of a State Machine is reached.

Final State consist of:

Definition

In UML, Final State is represented by double circle:

stateDiagram-v2
InitialState --> [*] : Finish
Loading

Equivalent Stateflows notation of States:

Lambda style

    /* fragment of State Machine definition */
    .AddState("InitialState", b => b
        .AddTransition<Finish>("final")
    )
    .AddFinalState("final")

If there is just one Final State in State Machine, shortened notation with default name can be used:

Lambda style

    /* fragment of State Machine definition */
    .AddState("InitialState", b => b
        .AddTransition<Finish>(FinalState.Name)
    )
    .AddFinalState() // no name provided here, default name used

Using lambda style here means that Final State is referred to by string name.

Typed style

    public class InitialState : IState
    { }

    /* fragment of State Machine definition */
    .AddState<InitialState>(b => b
        .AddTransition<Finish, FinalState>()
    )
    .AddFinalState()

Using typed style here means that Final State is represented by a class, in the example predefined FinalState class is used.

FinalState class can be used as a target for typed style Transitions if State Machine contains just one Final State. If there are more Final States, there is an important concern of State identity to be considered.

Overview
Installation
Behaviors
   State Machines
       Building blocks
           States
               State
               Composite State
               Orthogonal State
               Final State
           Pseudostates
               Choice
               Junction
               Fork
               Join
           Transitions
               Transition
               Default Transition
               Internal Transition
       Concepts
           Evaluation of Transitions
   Activities
       Building blocks
           Nodes
               Action Node
               Decision Node
               Merge Node
               Initial Node
               Final Node
               Input Node
               Output Node
               Fork Node
               Join Node
               Accept Event Action Node
               Send Event Action Node
               Data Store Node
               Structured Activity Node
               Iterative Activity Node
               Parallel Activity Node
           Flows
               Data Flow
               Control Flow
       Concepts
           Implicit fork and join
   Actions

Clone this wiki locally