Skip to content

Transitions

mikolaj-milewski edited this page Mar 26, 2025 · 12 revisions

Overview

Transition is the way to change state of State Machine.

In general, Transition consists of:

  • Trigger, type of Event that activates Transition,
  • Source, a State that transition is coming from,
  • Target, a State that transition is coming to,
  • Guard, logic that decides if Transition should happen,
  • Effect, logic that is run when Transition happens.

Types of Transitions

There are three types of Transitions:

  1. 'Regular' Transition that moves from one State to another,
  2. Internal Transition that has no Target State,
  3. Default Transition that has no explicit Trigger Event.

Transitions are always defined on the level of Source State.

Single State can have multiple Transitions triggered by various Event types. Moreover, there can be multiple Transitions triggered by the same Event type.

Definition

UML notation of Transition:

stateDiagram-v2
Source --> Target : Trigger [Guard] / Effect
Loading

Equivalent Stateflows notation of Transition:

Lambda style

    /* fragment of State Machine definition */
    .AddState("Source", b => b
        .AddTransition<Trigger>("Target", b => b
            .AddGuard(async c => true)
            .AddEffect(async c => {})
        )
    )
    .AddState("Target")

Using lambda style means that logic parts within Transition (Guard, Effect) are implemented directly in State Machine as lambdas.

Typed style

    /* fragment of State Machine definition */
    .AddState<Source>(b => b
        .AddTransition<Trigger, TriggerTransition, Target>()
    )
    .AddState<Target>()

Using typed style means that logic parts within Transition (Guard, Effect) are implemented as separate classes and referenced using typed overloads of Add* methods.

Logic

There are two places where logic can be injected into Transition of any type, both optional:

  1. Guard:
    • determines if Transition should happen,
    • must return bool value,
    • lack of Guard on Transition means that there is an implicit true-returning Guard,
    • should not cause any side effect,
    • can be called multiple times on multiple Transitions, even the ones which won't eventually happen.
  2. Effect:
    • is called when Transition happens, after OnExit of Source State and before OnEntry of Target State,
    • can cause side effects.

The way of adding logic to Transition varies depending on used declaration style. For more details, refer to Guards or Effects, respectively.

Evaluation

Topic is explained in Evaluation of Transitions.

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