Skip to content

5.4.2.2.4. Final State

Mikołaj Milewski edited this page Nov 12, 2026 · 1 revision

Final State

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

Definition fragment (inside the builder callback):

    /* 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:

Unnamed final-state shorthand

Definition fragment (inside the builder callback):

    /* 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
    { }

Definition fragment (inside the builder callback):

    /* 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.

Clone this wiki locally