Fact-checked by Grok 2 weeks ago

UML state machine

A UML state machine is a behavioral specification within the (UML) that models the dynamic behavior of a , object, or classifier through a finite set of , transitions triggered by events, and associated actions or activities. It represents discrete behavior as a where vertices denote (situations in which an condition holds for the modeled entity) and edges denote transitions (changes from one to another, often conditioned by guards and effects). UML distinguishes two primary kinds: behavioral state machines, which specify the complete life cycle of a reactive object including responses to external or internal events, and protocol state machines, which focus on the valid sequences of messages or operations (usage protocols) without detailing internal actions. Originating as an object-oriented extension of David Harel's statecharts formalism, UML state machines were introduced in UML 1.x and refined in subsequent versions by the () to support complex, concurrent behaviors through features like composite states, orthogonal regions, and pseudostates (e.g., , final, , and pseudostates). Every state machine includes a top-level region that organizes its , enabling nested structures for and via submachines or state refinements. These diagrams are particularly useful in for designing reactive systems, such as , user interfaces, and protocols, by visualizing how entities evolve over time in response to stimuli while ensuring completeness and consistency in behavioral models. The formalism emphasizes executability, with precise semantics defined in the UML superstructure to allow simulation, verification, and from state machine models.

Introduction

Definition and Purpose

A UML state machine is a graphical notation in the (UML) for specifying the behavior of entities, such as classes, objects, or components, in response to events by defining their states, transitions between those states, and associated actions. This formalism enables modelers to represent discrete, event-driven behaviors where the system responds differently depending on its current state, providing a structured way to visualize and document dynamic system aspects. The primary purpose of UML state machines is to model reactive systems, object lifecycles, and state sequences in software design, particularly in domains requiring precise control over timing and responses, such as embedded systems and real-time applications. They facilitate the analysis of complex interactions by focusing on how entities evolve over time in response to stimuli, aiding in requirements specification, verification, and implementation of reliable behaviors without delving into algorithmic details. UML distinguishes between two types of state machines: behavioral state machines, which describe all possible sequences of states an entity may enter, including internal actions and reactions to events; and state machines, which specify the permissible sequences of operation calls and messages on an entity's , emphasizing legal usage protocols without internal behavioral details. Behavioral state machines are suited for modeling complete lifecycles, while state machines focus on external constraints and preconditions for interactions. For example, a behavioral state machine can model a controller with states including red, green, and yellow, where transitions occur via time-based events to ensure safe sequencing. Similarly, an order processing system might employ states like pending, approved, shipped, and delivered, with transitions triggered by events such as payment receipt or logistics updates, illustrating how state machines capture business workflows.

Historical Context and Evolution

The concept of state machines in UML traces its origins to the 1980s, when David Harel introduced statecharts as a visual formalism to model complex reactive systems, extending traditional finite state machines (FSMs) with hierarchical nesting and orthogonality to mitigate issues like state explosion in concurrent behaviors. Harel's work, formalized in his 1987 paper, addressed key limitations of classical FSMs by allowing states to contain substates and enabling independent concurrent regions, which facilitated the modeling of systems with multiple orthogonal components without combinatorial growth in state count. This innovation was implemented in the Statemate tool, developed by i-Logix in collaboration with Harel, which provided executable semantics for statecharts and influenced subsequent modeling practices in . In the early 1990s, object-oriented modeling approaches further shaped the evolution of state-based notations. James Rumbaugh's (OMT), introduced in 1991, incorporated state transition diagrams as part of its dynamic model to capture the life history of objects through events and state changes, bridging with structural object-oriented design. Similarly, Bran Selic's Real-time Object-Oriented Modeling (ROOM) in the mid-1990s extended statecharts for real-time systems, emphasizing capsules with concurrent state machines and , which addressed challenges in distributed environments. These methodologies, including influences from Grady Booch's work on object lifecycles, converged to inform UML's behavioral diagrams. UML integrated statechart concepts upon its standardization by the () in November 1997 with UML 1.1, where statechart diagrams—later renamed state machines—were introduced to specify object behaviors in response to events, drawing directly from Harel's formalism and OMT's dynamic elements. A major advancement occurred with UML 2.0 in July 2005, which enhanced state machines with refined support for concurrency through and deeper , including the introduction of local transitions, allowing more scalable models of complex, multi-threaded systems while preserving the run-to-completion semantics. Further minor refinements in UML 2.5.1, released in December 2017, clarified aspects of the semantics, such as redefinable vertices in state machines. These evolutions, guided by 's revision task forces, progressively addressed FSM limitations by embedding and as core features, enabling UML state machines to model sophisticated reactive systems effectively.

Core Elements

States and Pseudostates

In UML state machines, states represent the units that capture the situations in which an object or system exhibits specific behaviors or conditions. A is a that models a situation during which some condition holds, and the object performs certain activities or waits for events. states, also known as or states, are indivisible units without substates, serving as the leaf nodes in the hierarchy. They depict moments when the system is stable and ready to respond to incoming events, often including internal behaviors such as entry actions (executed upon entering the state), do activities (ongoing behaviors), and actions (executed upon leaving). In notation, simple states are depicted as rounded rectangles containing the state name, with optional compartments for internal transitions or activities below. For instance, a simple state named "Idle" might represent a waiting for input, with an entry to initialize resources. Composite states extend simple states by enclosing one or more regions that contain substates, enabling hierarchical modeling to manage complexity, though the detailed nesting mechanics are addressed elsewhere. They are visually represented as larger rounded rectangles with internal boundaries for regions, which can be sequential (single-threaded) or orthogonal (concurrent via dashed lines). A composite state like "Processing Order" might encompass substates for validation and fulfillment, allowing the system to enter a specific substate upon . Pseudostates are transient vertices that do not represent actual states but serve as markers or connectors within the state machine to control flow and initialization. Unlike regular states, pseudostates cannot hold invariants or execute activities and are not instantiable; they facilitate entry, exit, branching, and tracking. The UML specification defines several kinds, each with distinct notation and semantics. The initial pseudostate denotes the default starting point of a region or the entire state machine, from which exactly one outgoing fires without a or to enter the initial substate. It is graphically shown as a small solid . In a login process example, an initial pseudostate might to a "Enter Credentials" simple state upon state machine activation. The final pseudostate indicates the completion of a or the state machine, signaling termination with no further processing in that scope; multiple finals can exist in orthogonal regions. It appears as a circle enclosing a smaller solid black circle, often called a bullseye. Continuing the login example, a final pseudostate could mark successful , ending the process. History pseudostates allow resumption of a composite state at a previously active substate after interruption. The shallow history (denoted by a circle with an "H" inside) restores only the immediate substate, while the deep history (circle with "H*" ) restores the full nested configuration. These are useful for scenarios like pausing and resuming workflows. Choice pseudostates enable dynamic conditional branching based on guards evaluated at , modeled as a diamond shape with one incoming and multiple outgoing transitions. They support (XOR) decisions without explicit events. Junction pseudostates facilitate static merging of incoming transitions or splitting into outgoing ones based on guards, represented as a small black circle with short cross lines; they are useful for converging paths without dynamic evaluation. Entry and exit point pseudostates provide designated portals for entering or leaving composite states, especially in orthogonal regions. An is a small circle on the composite state's boundary, and an exit point is a circle with an "X" inside, allowing transitions to connect externally while encapsulating internals. Fork pseudostates split a single incoming transition into multiple concurrent transitions targeting orthogonal regions, initiating parallel execution paths; they are represented as a short thick with one incoming arrow and multiple outgoing arrows. Join pseudostates synchronize multiple incoming transitions from orthogonal regions into a single outgoing transition, waiting for all incoming paths to complete before firing; they are also depicted as a short thick horizontal bar. Terminate pseudostates explicitly terminate the execution of the entire state machine, preventing further event processing; they are shown as a circle enclosing an X.

Events

In UML state machines, events represent detectable occurrences or conditions that can trigger transitions between states, serving as the primary stimuli for behavioral changes in a modeled . These events are processed according to the run-to-completion semantics, where an event is dispatched from an event pool associated with the state machine's context classifier and evaluated against applicable transitions. The event pool acts as a for incoming event occurrences, ensuring that events are handled one at a time without during processing. UML defines four main types of events, each suited to different kinds of stimuli. Call events occur when an of the classifier is invoked synchronously, such as a method call that blocks the sender until completion; their notation in transition triggers is simply the operation name followed by parameters if any, e.g., processPayment(amount). Signal events, in contrast, are triggered by the asynchronous receipt of a signal defined in the classifier's receptions, allowing non-blocking communication like messages in distributed systems; they are denoted as the signal name, e.g., coinInserted(). Time events are relative or absolute timing specifications that fire after a or at a specific point, notated as after(duration) for relative time (e.g., after(30 seconds)) or at(timeExpression) for absolute; these are useful for modeling timeouts or scheduled behaviors. Change events detect when a evaluating the state of the system becomes true, such as a being crossed, and are written as when([condition](/page/Condition)), e.g., when(inventory < 5). The role of events in state machine behavior centers on their dispatch and consumption: upon occurrence, an event instance enters the event pool of the owning instance or behavioral feature, from which it is dequeued and matched against transition triggers in the current state configuration. If no transition fires, the event is discarded unless deferred in the current state; otherwise, it initiates the transition selection process, potentially leading to state changes. This queuing mechanism supports concurrent event handling in complex systems while maintaining deterministic execution. Events may carry parameters providing contextual data, such as values or objects, which can be accessed in guards or actions. A representative example illustrates the distinction between call and signal events in a vending machine state machine. A selectItem(productId) call event might synchronously invoke an operation to process a user's button press, immediately validating and deducting from the balance if sufficient funds exist, reflecting a direct, blocking interaction. In contrast, a coinInserted(amount) signal event arrives asynchronously from a coin acceptor hardware interrupt, queuing independently without halting other operations, allowing the machine to handle multiple insertions fluidly before processing. Time events like after(60 seconds) could trigger an idle state from a waiting state if no selection occurs, while a change event such as when(balance >= price) enables the transition to dispensing upon accumulation of sufficient asynchronous signals.

Transitions and Guards

In UML state machines, transitions represent directed relationships that connect a source state to a target state, specifying how the system responds to events by changing its state. A transition is triggered by an event and may include an optional guard condition and an effect, collectively notated as event [guard] / action. This triplet allows precise modeling of dynamic behavior, where the event initiates the potential change, the guard evaluates whether the transition is permissible, and the action denotes any immediate behavior executed during the transition. Guard conditions are Boolean expressions that must evaluate to true for a transition to fire upon occurrence of its triggering event; they are dynamically assessed based on the current context, including extended state variables and event parameters. Guards are typically expressed using the (OCL) or simpler logical expressions, ensuring they reference only elements accessible at evaluation time, such as state attributes or event data. To prevent nondeterministic behavior, guards on outgoing transitions from the same source state for the same event must be mutually exclusive, meaning at most one can be true at any given time. UML distinguishes between external and local transitions based on their scope within hierarchical structures. An external transition connects states potentially across different composite boundaries, triggering full exit actions from the source state (and its enclosing composites) and entry actions into the target state (and its enclosing composites). In contrast, a local transition operates solely within a composite state between its substates, executing only the substate exit and entry actions without affecting the enclosing composite's behaviors; further details on their effects appear in the section on local and external transitions. Both types use the same notation but differ in graphical rendering: external transitions show a solid with a head, while local transitions may appear as a bent staying within the composite . For illustration, consider an system's authentication flow. From an "" state, a card insertion event triggers transitions to a "Card Inserted" substate. Subsequent PIN entry might then lead to parallel transitions: one to "Authenticated" if [pinValid] (a checking the entered PIN against stored credentials), or to "PIN Error" if [pinInvalid] and retry attempts remain. This ensures the machine only proceeds to transaction states under verified conditions, with the guards [pinValid] and [pinInvalid] being mutually exclusive.

Behaviors and Actions

Actions and Activities

In UML state machines, actions represent , executable behaviors that specify instantaneous responses to events or state changes, such as invocations or assignments, ensuring they complete without interruption. These behaviors are modeled as opaque expressions or references to operations and form the basic units of execution within the state machine's dynamics. Activities, in contrast, denote extended, ongoing behaviors that may involve complex workflows, often realized through references to UML activity diagrams for detailed specification. Unlike actions, activities can run concurrently and for indeterminate durations, capturing processes that persist while a state remains active. They provide a mechanism to decompose intricate operations beyond simple atomic steps. Actions and activities attach to various elements in a state machine, including transitions as effects that execute upon firing (after guards but before entering the target state) and states as do-activities for concurrent execution during state residence. Entry and exit actions on states offer additional attachment points for behaviors triggered by state ingress or egress, though their precise invocation sequences are addressed separately. For instance, a simple on a might log an event occurrence, such as recording a user input in a system log via a method call like logEvent("inputReceived"). In comparison, an activity attached as a do-activity in an "Order Processing" state could reference an modeling the full payment processing workflow, including validation, charging, and confirmation steps in an application.

Entry, Exit, and Internal Transitions

In UML state machines, entry actions represent behaviors that are automatically executed upon entering a , irrespective of the incoming . These actions are particularly useful for performing initialization tasks, such as setting initial values for local variables or allocating resources required during the state's lifetime. As defined in the UML specification, entry actions are specified within the internal activities compartment of a and notated using the keyword "entry" followed by a slash and the action expression, for example, "entry / initializeBuffer()". Exit actions, conversely, are behaviors triggered automatically when leaving a state, regardless of the outgoing transition. They serve purposes like cleanup operations, such as releasing resources, logging state completion, or saving persistent data to ensure proper termination. The UML notation for exit actions mirrors that of entry actions but uses the "exit" keyword, placed in the same internal activities compartment, as in "exit / cleanupResources()". According to the specification, exit actions execute after any ongoing do-activities in the state have completed, maintaining the integrity of the state's ongoing processes. Internal transitions enable a state to respond to specific events without exiting or re-entering the , thus avoiding the invocation of entry or exit actions. This is essential for handling minor events, such as status updates or notifications, that do not warrant a full change. In the UML semantics, internal transitions have higher than outgoing transitions from the same ; if both are applicable to an event, the internal transition takes precedence. They are notated either as self-s (arrows looping back to the ) or listed in a dedicated internal transitions compartment with the event trigger, optional guard, and , for example, "error / logError(message)" without a target vertex. The execution semantics for these elements follow a strict order within the run-to-completion model of UML state machines: upon state entry, the entry action executes first, followed by any do-activity (a continuous behavior during the state's residence); upon exit, the do-activity completes before the exit action runs. This sequencing ensures that initialization precedes ongoing state behavior and cleanup follows it, preventing resource leaks or inconsistent states. For instance, in a "Processing Order" state, an internal transition might handle a "lowPriorityAlert" event by simply incrementing a counter and logging it, without disrupting the processing do-activity.

Extended States and Variables

In UML state machines, extended states augment the basic states by incorporating quantitative through extended state variables, which capture the history and context of the system's behavior. These variables represent the program's and allow the state machine to model dynamic conditions without requiring an increase in the number of states. For instance, instead of defining separate states for every possible in a retry , a single can track the number of attempts, enabling the machine to respond based on its current value. This concept, rooted in the UML , combines the qualitative aspect of the current with the quantitative values of these variables to form the complete extended . Variables in UML state machines can be attributes of the owning classifier (such as an object or ) or local to the state machine instance, and they are updated through actions triggered by events or transitions. These updates occur during state entry, exit, or internal processing, allowing the variables to influence future behavior. The role of such variables is to introduce into what would otherwise be a memoryless , facilitating the modeling of real-world systems where past events affect present decisions, such as incrementing a after each failed attempt. By maintaining these variables, UML state machines can handle complex scenarios efficiently, as demonstrated in examples like a state machine where a key_count variable decrements with each keystroke until reaching zero, triggering a state. A practical example is a network state machine with an extended state including a timeout that measures elapsed time since the last activity. If an occurs while the machine is in a "Connected" state, an might reset the timeout to zero; otherwise, a condition like [timeout > 30] on a to "Disconnected" evaluates the variable to decide whether to terminate the . This approach ensures that the state machine remains concise while incorporating time-sensitive or accumulative logic, directly supporting the use of variables in guards and actions as defined in the UML standard.

Execution Semantics

Run-to-Completion Model

The model constitutes the core execution semantics for UML state machines, stipulating that the processing of each occurs in a discrete, atomic step that fully completes before the state machine can respond to any subsequent . In this model, a step initiates upon the dispatch of an to the state machine, encompassing the evaluation of transitions, execution of associated actions, and stabilization into a new configuration, after which the machine enters an idle state awaiting the next queued . Central to the RTC model are principles of non-preemption and event queuing: during a step, no incoming events can interrupt the ongoing execution, with all pending events instead accumulated in an event pool for sequential processing once the current step concludes. This ensures that actions—such as entry or exit behaviors triggered within the step—are completed without interference, maintaining the integrity of the state machine's configuration throughout. The implications of the RTC model include guaranteed deterministic behavior in single-threaded implementations, as it precludes race conditions or nondeterministic interleaving that could arise from concurrent event handling within a single state machine. By enforcing atomicity, it simplifies and , though it may introduce in systems where long-running actions delay responsiveness to time-sensitive events. For instance, in an event-driven modeling a , the RTC model ensures that a complete response to a button press —including and associated computations—is processed atomically before queuing and handling a subsequent expiration , thereby avoiding partial updates or inconsistent .

Transition Execution Sequence

In UML state machines, the execution of a adheres to a strict to maintain behavioral , especially in hierarchical . Upon firing a , the first invokes the behaviors of the source , proceeding outward through its containing composite states up to the least common (LCA) with the target ; this ensures that all relevant inner-to-outer exits are completed before any is triggered. Next, the 's own —such as an action or activity—is executed. Finally, the entry behaviors of the target are invoked, starting from the LCA and proceeding inward to the target, thereby reestablishing the nested . This ordered propagation through the is foundational to UML's , as defined in the standard. When multiple transitions are eligible for the same event, prioritizes the highest- one, typically the originating from the innermost or one explicitly assigned higher via model annotations; lower- transitions are deferred or ignored until the selected one completes, preventing nondeterministic . This mechanism applies dynamically during , ensuring that deeper, more specific reactions take precedence over shallower ones. In nested structures, the sequence interrupts and terminates any ongoing do-activities within the traversed states to avoid ; this ensures isolation of the step without preserving interrupted behaviors across the . For instance, consider a hierarchical state machine modeling a vehicle's , where the current state is "Driving > Cruising > SpeedMaintain" and an event triggers a to "Parked > Secured." The sequence executes as follows: "SpeedMaintain" (e.g., stop throttle adjustment), "Cruising," "Driving" (e.g., log departure), perform the effect (e.g., apply brakes), enter "Parked" (e.g., initialize parking mode), and enter "Secured" (e.g., ). This example illustrates how the dictates the outward-then-inward flow, with do-activities like continuous speed monitoring interrupted and terminated during the process. This detailed sequence operates within the enclosing run-to-completion model, where the entire process is atomic relative to external events.

Local and External Transitions

In UML state machines, external transitions represent the standard and default type of transition, where firing the transition results in a complete exit from the source —including all its enclosing composite states up to the least common with the target—and a subsequent entry into the target and its enclosing states, executing all relevant exit and entry actions along the path. This full traversal ensures that the state machine properly handles changes across the hierarchy, making external transitions suitable for shifts between distinct high-level states. Local transitions, by contrast, are confined to the interior of a single composite state, connecting a source vertex to a target vertex both nested within that composite. When triggered, a local transition executes without causing an exit from or entry to the enclosing composite state itself, thereby avoiding the execution of the composite's exit or entry actions and limiting effects to the involved subvertices. Unlike self-transitions (which are classified as internal), local transitions require distinct source and target vertices and can only occur within composite states. In diagrams, local transitions are visually indicated by arrows that remain entirely within the composite state's boundary, without crossing it, distinguishing them from external transitions that may span across boundaries. The distinction between local and external transitions enables more granular control over state machine behavior in hierarchical models. Local transitions promote efficiency by allowing rapid changes among substates—such as switching between "insert mode" and "select mode" within an "" composite in a application—without reinitializing the parent composite or disrupting its ongoing context. External transitions, however, are essential for broader state changes that necessitate full traversal, such as exiting the "" composite entirely to enter a "saving" state. UML 2.5 introduced clarifications to the semantics of local transitions to address prior ambiguities in hierarchy traversal and action execution, ensuring that their confinement to substructures yields more predictable and consistent outcomes in complex designs. These refinements, carried forward into UML 2.5.1 with minor adjustments, emphasize that local transitions do not propagate effects beyond the composite, aligning with the run-to-completion model while supporting modular state refinements.

Advanced Structures

Hierarchical Nesting

In UML state machines, hierarchical nesting is achieved through composite states, which serve as containers for sub-machines and enable the organization of complex behaviors into structured hierarchies. A composite state is defined by the property isComposite = true and contains one or more regions, each of which can hold nested states and transitions, allowing for direct substates (immediately contained) or transitive nesting (deeper levels). This structure permits the encapsulation of related behaviors within a single enclosing state, reducing the overall complexity of the diagram by grouping elements logically. Upon entry into a composite state, execution begins with initial transitions from an initial pseudostate, typically represented as a filled , to one or more substates within its s. Each must have an initial connected by a default , which is taken implicitly unless overridden by an explicit incoming targeting a specific substate; absence of an initial pseudostate may render the model ill-formed. These initial s ensure a well-defined starting point for the sub-machine, facilitating sequential of nested behaviors. Pseudostates like the initial play a crucial role in this entry mechanism. The primary benefits of hierarchical nesting include enhanced and the promotion of shared behaviors across levels. By decomposing large state machines into reusable composite units, nesting supports , making models easier to maintain and extend without . Enclosing states can define shared entry, exit, and doActivity behaviors that apply to all substates, or common transitions that substates inherit, thereby enabling efficient reuse of logic and reducing duplication in specifications. Event propagation in nested structures ensures robust handling by allowing unhandled events in a substate to bubble up to the enclosing composite state. If an event does not trigger a transition or is deferred within the inner state, it is propagated outward for potential processing at higher levels, preventing loss of events while maintaining hierarchical control. Events deferred in a state remain queued until the state is exited or the event is explicitly handled. For example, consider a state machine modeling a where a top-level "Playing" composite state contains substates such as "LevelInProgress," "Paused," and "GameOver." Upon entering "Playing," an initial from the region's initial pseudostate activates "LevelInProgress," inheriting shared entry actions like loading game assets from the composite. An unhandled "pause" in "LevelInProgress" propagates to "Playing," triggering a to "Paused," which reuses the enclosing state's doActivity for continuity. This nesting modularizes the play mode, allowing sub-modes to share common pause/resume without .

Orthogonal Regions

Orthogonal regions in UML state machines enable the modeling of concurrent, independent behaviors within a single composite state, allowing multiple sub-machines to operate in without direct interference unless explicitly synchronized. A composite state is orthogonal when it contains two or more regions, visually represented by dashed lines dividing the state into separate compartments. Each region functions as a self-contained state machine fragment, possessing its own set of states, transitions, and pseudostates, including dedicated initial and final pseudostates to manage entry and completion independently. This structure supports the representation of systems where parallel activities, such as processing user inputs and handling network communications, can evolve simultaneously. Synchronization between orthogonal regions occurs through specific pseudostates that coordinate transitions across regions. A fork pseudostate splits an incoming transition into multiple concurrent transitions, each targeting a in a different , thereby initiating parallel execution without evaluating guards sequentially. Conversely, a join pseudostate merges outgoing transitions from multiple regions into a single transition, firing only when all incoming transitions from the specified regions have completed and their guards evaluate to true. These mechanisms ensure controlled interaction in concurrent scenarios, such as synchronizing the completion of in one with status updates in another before proceeding to a subsequent . In terms of execution semantics, orthogonal regions operate under the run-to-completion model extended for concurrency, where each region processes events independently during a state machine step. Events are broadcast to all active regions upon occurrence, potentially triggering at most one transition per bottom-level region per event, while entry and exit actions of the enclosing composite state execute only once regardless of the number of regions. A composite state remains active as long as at least one of its regions is active, and the overall state machine completes an execution step only after all regions have finished their run-to-completion processing for the current event. The completion of all regions in an orthogonal state can implicitly trigger an outgoing transition from the composite state, signaling the end of concurrent activities. A practical example of orthogonal regions is modeling a networked , such as a , where one region handles interactions (e.g., button presses transitioning between display modes) and another manages communication protocols (e.g., sending status updates over ), with a fork pseudostate initiating both upon device and a join synchronizing them before entering a maintenance . This approach, often nested within hierarchical states for added structure, facilitates the design of complex, reactive systems exhibiting true parallelism.

Event Deferral and History States

In UML state machines, event deferral is a mechanism that allows certain events to be temporarily postponed rather than immediately discarded when they occur in a state where they cannot be handled. When an event is deferred in a state, it is placed into the event pool of the state machine and retained until the machine enters a state where the event is no longer deferred, at which point it becomes eligible for processing according to the run-to-completion semantics. This feature is particularly useful for managing out-of-order or low-priority events, such as deferring a low-priority signal in an idle state until a more appropriate active state is reached, ensuring that critical events are not lost while avoiding unnecessary state changes. The notation for deferred events involves specifying a list of deferrable events within a dedicated compartment of the symbol, using the event1, event2, ... / defer. Deferred events are associated with the via the deferrableTrigger property, and conflicts in deferral across orthogonal regions are resolved non-deterministically, though this is handled within the broader execution model. Upon entry to a that does not defer the event, it is automatically recalled from the pool and evaluated as if it had just occurred, maintaining the original order in the event queue. History states in UML state machines are pseudostates that enable the resumption of a previous substate within a composite state after an interruption, providing a form of state . There are two variants: shallow history and . A shallow history pseudostate remembers only the most recent active direct substate (at the immediate level) of the enclosing composite state or region; upon re-entry, the state machine transitions to that substate, or to the default initial substate if no exists. In contrast, a deep history pseudostate captures the complete active , including all nested substates recursively throughout the hierarchy; re-entry restores the entire remembered subtree, again defaulting to the initial if none is recorded. Graphically, history pseudostates are denoted by a small open circle containing an "H" for shallow history or "H*" for , placed within the boundary of the composite state it applies to, with an outgoing transition to the remembered substates or defaults. This mechanism is valuable for modeling interruptible processes, such as a in a phone call machine where, after transitioning to a "hold" state and returning, the history state resumes the exact prior subconfiguration (e.g., "connected" with active participants) rather than resetting to an initial setup. At most one history pseudostate of each type is permitted per region of a composite state to avoid in restoration.

Limitations and Extensions

Key Differences from Traditional FSMs

Traditional finite state machines (FSMs), exemplified by Mealy and Moore models, consist of a flat set of states with transitions triggered by inputs that produce outputs, but they do not support hierarchical structure or concurrent execution. These models are limited to sequential behavior, leading to rapid complexity growth—known as state explosion—in systems with many interacting components, where the number of states can grow exponentially with added features. UML state machines address these limitations through key extensions, including hierarchical nesting, where states can contain substates organized into regions, allowing modular decomposition of behavior and reuse of state logic to mitigate state explosion. For instance, in modeling a system, a top-level "Operational" state can nest substates for "," "Yellow," and "Red" phases, avoiding the need for a flat with hundreds of transitions for handling or modes. Additionally, orthogonal regions enable concurrency by partitioning a composite state into independent sub-behaviors that evolve simultaneously, such as coordinating engine and transmission controls in an automotive system. UML also introduces history states (shallow or deep) to automatically restore prior substate configurations upon re-entry, and supports actions on states—including entry, exit, and do activities—beyond just transition effects, providing richer behavioral specification. A specialized variant, protocol state machines, focuses on specifying valid message sequences and preconditions/postconditions without full execution semantics, differing from behavioral state machines by omitting do activities and emphasizing interface protocols. These extensions enhance scalability for complex, real-time systems by promoting modularity and parallelism, while the run-to-completion (RTC) model provides formal semantics, ensuring events are processed atomically to prevent race conditions. Overall, UML state machines retain FSM benefits like and verifiability but scale to industrial applications, such as , where traditional FSMs become unmanageable.

Limitations of UML State Machines

Despite the hierarchical and orthogonal features introduced to mitigate , UML state machines still suffer from state explosion in large-scale systems, where the number of possible configurations grows exponentially, complicating and even after nested structures. Tool support for handling such varies significantly across implementations, with many tools struggling to scale for industrial applications without custom extensions. Semantic ambiguities persist in UML state machines, particularly regarding concurrent execution, where the official semantics leave nondeterministic choices in event dispatching and activity synchronization unclear, leading to inconsistent interpretations across tools. Timing specifications are another gap, as UML state machines provide only basic time events like "after(d)" without formal semantics for durative actions or precise constraints, necessitating integration with other UML diagrams such as timing or sequence diagrams for real-time modeling. UML state machines emphasize structural aspects like states and transitions over explicit data flow, implicitly handling data via events or guards, which can obscure data dependencies and complicate integration with data-centric models. Protocol state machines, intended for specifying interface contracts, are less expressive for capturing non-contractual or internal behaviors, limiting their use in full system modeling beyond observable protocols. To address these limitations, best practices include through hierarchical and iterative refinement, which reduces by encapsulating behaviors in reusable submachines. Compared to alternatives like Petri nets, UML state machines offer graphical intuitiveness but fall short in formal concurrency analysis, where Petri nets provide stronger mathematical foundations for verifying parallel interactions without ambiguities. These issues remain persistent in UML 2.5.1, with ongoing calls in the research community for enhanced formal verification support to resolve ambiguities and improve scalability.

References

  1. [1]
    [PDF] ISO/IEC 19505-1:2012(E) - Object Management Group
    Apr 8, 2012 · ... Specification (PAS) of the OMG Unified Modeling Language (UML) specification. This International Standard is related to: • ITU-T ...Missing: download | Show results with:download
  2. [2]
    About the Precise Semantics of UML State Machines Specification ...
    Syntactically, this specification extends fUML with a (large) subset of the abstract syntax of state machines as given in the OMG Unified Modeling Language ...
  3. [3]
    None
    Below is a merged summary of Chapter 14: State Machines (UML 2.5.1) that consolidates all the information from the provided segments into a single, comprehensive response. To retain as much detail as possible, I will use a structured format with tables where appropriate, followed by a narrative summary for semantics, attachment points, and URLs. This approach ensures all details (e.g., section numbers, page references, and specific semantics) are preserved while maintaining clarity and density.
  4. [4]
    UML State Machine Diagrams - Overview of Graphical Notation
    This document describes UML 2.5 and is based on OMG™ Unified Modeling Language™ (OMG UML®) 2.5 specification [UML 2.5 FTF - Beta 1]. All UML diagrams were ...
  5. [5]
    A crash course in UML state machines: Part 1 - Embedded
    Mar 9, 2009 · In this article series, I briefly introduce UML state machines that represent the current state of the art in the long evolution of these techniques.
  6. [6]
    UML Protocol State Machine Diagrams
    Protocol state machine is a specialization of behavioral state machine and is used to express usage protocol or lifecycle of a classifier. It specifies which ...
  7. [7]
    UML state machine diagrams examples
    Purpose: An example of UML protocol state machine diagram showing thread states and thread life cycle for the Thread class in Java™. Summary: Thread is a ...<|control11|><|separator|>
  8. [8]
    State Machine Diagrams | Unified Modeling Language (UML)
    Apr 8, 2025 · A State Machine Diagram is used to represent the condition of the system or part of the system at finite instances of time.
  9. [9]
    Statecharts: a visual formalism for complex systems - ScienceDirect
    Harel D. Statecharts: A visual approach to complex systems. Department of Applied Mathematics, The Weizmann Institute of Science (1984). CS84- ...Missing: history | Show results with:history
  10. [10]
    The STATEMATE semantics of statecharts - ACM Digital Library
    We describe the semantics of statecharts as implemented in the STATEMATE system. This was the first executable semantics defined for the language.
  11. [11]
    [PDF] UML Summary - Object Management Group
    A Request for Proposal (RFP) issued by the Object Management Group. (OMG) ... language, state machine semantics, types, interfaces, components, collaborations,.
  12. [12]
    [PDF] A Crash Course in UML State Machines - Quantum Leaps
    In the UML specification, every state machine has a top state (the abstract root of every state machine hierarchy), which contains all the other elements of the ...
  13. [13]
    About the Unified Modeling Language Specification Version 1.1
    The Unified Modeling Language (UML) is a language for specifying, constructing, visualizing, and documenting the artifacts of a software-intensive system.
  14. [14]
    About the Unified Modeling Language Specification Version 2.5.1
    A specification defining a graphical language for visualizing, specifying, constructing, and documenting the artifacts of distributed object systems.
  15. [15]
  16. [16]
    Bank ATM. - Behavioral state machine UML diagram example
    This is an example of UML behavioral state machine diagram showing Bank Automated Teller Machine (ATM) top level state machine. ATM is initially turned off.
  17. [17]
    State Machines and UML Statecharts
    Internal and Self Transitions. Internal Transitions. Actions triggered by an event with no state change; Distinct from exit/entry actions; E.g. increment ...
  18. [18]
    Appendix B. State Machine Concepts - Spring
    An extended state is a special set of variables kept in a state machine to reduce number of needed states. Transition: A transition is a relationship between a ...B. 1 Quick Example · B. 2 Glossary · B. 3.2 Pseudo States
  19. [19]
    None
    ### Summary of UML State Machine Transition Execution Sequence
  20. [20]
    [PDF] A Formal Semantics for Complete UML State Machines with ... - LIPN
    We define the transition execution sequence based on a transition to keep the semantics consistent with entry behaviours. Basic Interleave Execution Step. If ...<|control11|><|separator|>
  21. [21]
  22. [22]
    Introduction to Hierarchical State Machines (HSMs) - Barr Group
    May 4, 2016 · Due to the phenomenon known as "state explosion," the complexity of a traditional FSM tends to grow much faster than the complexity of the ...Missing: key | Show results with:key
  23. [23]
    [PDF] Formalizing UML State Machines for Automated Verification - arXiv
    Jul 24, 2024 · The use of composite states or submachine states allows to define state machines in a hierarchical manner. ... https://www.omg.org/spec/UML/2.5.1/ ...
  24. [24]
    Formalizing UML State Machines for Automated Verification
    In this section, we focus on the latest stable version, i.e., UML 2.5.1 [170]. However, the various works surveyed here can address various versions of UML, ...
  25. [25]
    On formalizing UML state machines using ASMs - ScienceDirect
    In this section, we discuss some ambiguities in the official semantics of UML state machines [1] which are resolved in the ASM model and show how the UML ...
  26. [26]
    [PDF] Model Checking Timed UML State Machines and Collaborations
    We have described procedures for translating timed UML state machines and UML collaborations with time constraints into UPPAAL timed automata. The ...
  27. [27]
    [PDF] Analyzing Data Flows of State Machines
    This paper proposes a common meta-model capable of holding both state machine and data flow semantics, two of the most used behaviour models. This is done so.Missing: overemphasis | Show results with:overemphasis
  28. [28]
    Formalising concurrent UML state machines using coloured Petri nets
    Aug 12, 2016 · In this paper, we propose a formalisation of UML state machines using coloured Petri nets.