Skip to content
mikolaj-milewski edited this page Mar 18, 2025 · 8 revisions

Overview

State represents stable configuration of State Machine.

In general, State consist of:

  • Name, uniquely identifying State within State Machine,
  • Parent State, if State is a substate of Composite State or Orthogonal State,
  • OnEntry, logic that is executed when State is entered,
  • OnExit, logic that is executed when State is exited,
  • OnInitialize, logic that is executed when State is initialized (Composite and Orthogonal States only),
  • OnFinalize, logic that is executed when State is finalized (Composite and Orthogonal States only),
  • Set of outgoing Transitions.

Types of States

There are four types of States:

  1. Simple State that can have any number of outgoing Transitions,
  2. Composite State that can have any number of outgoing Transitions and any number of States (called its substates) having their own Transitions,
  3. Orthogonal State that is similar to Composite State, but its substates are grouped in any number of Regions that are considered orthogonal / parallel,
  4. Final State that marks the end of State's flow and can't have any outgoing Transitions nor OnEntry / OnExit logic.

Definition

UML notation of two States connected by Transition:

stateDiagram-v2
SourceState --> TargetState
Loading

Equivalent Stateflows notation of States:

Lambda style

    /* fragment of State Machine definition */
    .AddState("SourceState", b => b
        .AddDefaultTransition("TargetState")
    )
    .AddState("TargetState")

Using lambda style means that States are represented by string names passed as parameters to Add*State methods.

Typed style

    /* fragment of State Machine definition */
    .AddState<SourceState>(b => b
        .AddDefaultTransition<TargetState>()
    )
    .AddState<TargetState>()

Using typed style means that States are represented by classes that are referenced in typed overloads of Add*State methods. Such classes must implement proper interfaces - refer to detailed description of State, Composite State or Orthogonal State for more.

Logic

There are two places where logic can be injected into State (except Final State), both optional:

  1. OnEntry:
    • is called whenever State is entered,
    • can cause side effects.
  2. OnExit:
    • is called whenever State is exited,
    • can cause side effects.

The way of adding logic to States varies depending on used declaration style. For more details, refer to OnEntry or OnExit, respectively.

For Composite and Orthogonal States, there are two additional logic units:

  1. OnInitialize:
  2. OnFinalize:

Deferring Events

Each State, regardless of its type, can defer any number of Events.

Deferring an Event means that whenever State Machine Behavior receives an Event which is not consumed in current configuration of States (there are no Transitions triggered by this Event), Event instance is serialized and stored for future use. When State Machine instance changes current configuration of States, Stateflows checks if there are any stored Events that are no longer deferred and if it is the case, immediately dispatches them to this Behavior instance.

Event can be deferred using AddDeferredEvent<TEvent>() method on the level of State:

    /* fragment of State Machine definition */
    .AddState("SourceState", b => b
        .AddDeferredEvent<TargetState>()
    )

State cannot defer an Event which is triggering any of its 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