Understanding Stm Diagram State and Transition
State machine diagrams in SysML are powerful tools for visualizing the behavior of complex systems. This article will guide you through the basic concepts of state machine diagrams and explain important points to consider when creating such diagrams.
1. Introduction to State Machine Diagrams
A state machine diagram graphically represents the various states of a system and the transitions between those states. This tool clearly shows how a system changes over time in response to specific events. For example, it can be used to model the behavior of a variety of systems, such as software applications, mechanical devices, or process flows.
2. Purpose and Importance of State Machine Diagrams
State machine diagrams are very useful when you want to better understand the dynamic aspects of a system. This helps developers and designers clearly define the behavior of the system and accurately document the specifications of its behavior. Additionally, many modern modeling tools provide the ability to automatically generate production-quality code based on these diagrams, which is a huge advantage that can simplify and increase the efficiency of the development process.
3. When should you use a state machine diagram?
State machine diagrams are very useful when a system or component has various states and contains logic to transition between these states. They can be created at any point from the early stages of system design through maintenance, and are especially valuable when dealing with systems that require complex logic or state management.
4. Precautions for use
State machine diagrams are primarily used to represent the classifier behavior of a block (i.e., the behavior that begins when a block is created and completes when it is deleted). Not all systems or components operate in a stateful manner, so this diagram is only appropriate in certain situations.
5. Understanding through real-life examples
For example, let’s model the operation of an ATM machine with a state machine diagram. An ATM machine can have states such as ‘Standby mode’, ‘Save card’, ‘Confirm pin number’, ‘Process transaction’, ‘Complete transaction’, etc. Each user action (e.g. inserting a card, entering a pin number, selecting an amount) triggers a state transition, which provides a clear understanding of the behavior of the system.
Basic structure of state machine diagram frame
1. Structure of diagram header
The header of a state machine diagram follows this format: stm [state machine] state machine name [diagram name]
Things to note here:
- Diagram type (
stm
) : This is an abbreviation for state machine diagram.stm
provides a standard way to identify this diagram in SysML. - State Machine Name : The name of the specific state machine that the diagram represents. This specifies the main target of the diagram.
- Diagram Name : Optionally, you can provide an additional name for the diagram. This can provide additional information about the purpose of the diagram or what it contains.
The model element type called “state machine” in square brackets is usually omitted. This is because the stm
abbreviation already clearly identifies a state machine diagram.
2. State machine as a namespace
A state machine is a type of namespace. That is, it has a structure that can contain a named set of elements (specifically states and transitions). These elements are represented visually within a state machine diagram frame.
3. Difference between state machine and state machine diagram
Importantly, state machines and state machine diagrams are not the same thing. A state machine refers to a model element, and a state machine diagram is a visual tool through which that model element is represented. This distinction is very important in understanding and using state machine diagrams.
Understanding states in state machine diagrams
States are key elements in SysML state machine diagrams that represent important conditions within the life cycle of a system or component (block). States allow designers to define how a system reacts and performs certain actions under certain conditions. It plays an important role in modeling and predicting the dynamic behavior of the system.
1. Simple State
A simple state represents the most basic condition a system or component can have. It represents the basic operating state of the system, without any additional substates, and can transition to other states depending on certain events.
- Notation of simple states : Simple states are represented by rectangles with rounded corners. This form is used within a state machine diagram to visually represent a specific state of the system. Each state must contain at least a name block that specifies the name of the state. The name helps clearly identify the state and summarize its function. However, SysML does not present specific rules for naming states. Giving meaningful names to states can sometimes be a challenge for designers.
- Internal operations and transitions : A simple state may optionally contain a second compartment, which lists the internal operations and transitions that can occur in that state. SysML defines three types of internal behavior:
- **Entry (entry action): This is an action executed when entering the ** state. The entry operation is completed before the state machine can process new events. This means that the entry operation is atomic.
- Exit (exit action): This is the action executed when leaving the state. The exit operation is executed before the transition out of the state occurs and is also atomic.
- Do (perform action): An action that is continuously executed while in the state. The ‘Do’ operation is non-atomic and can be interrupted by a new event.
- Expression of movement : Each internal operation begins with a keyword (entry, exit, do) followed by a slash (/), followed by the name of the opaque expression or operation. An opaque representation refers to a description of an action written in a specific language, where the name of the action may refer to an activity, interaction, or other state machine defined within the model.
2. Composite State
A composite state is a state that contains one or more substates. This means that states can be more granular, which is useful when modeling the behavior of complex systems. Complex states can contain substates within them, allowing you to model detailed behavior within specific conditions of the system.
- Notation of complex states : Composite states are represented using rectangles with rounded corners. It uses the same basic form as a simple state, but a complex state can additionally contain a third compartment that can contain substates nested within it. This compartment represents the various substates that can occur within a composite state.
- Characteristics of complex states :
- Internal substates: A composite state can contain one or more internal substates, which means that when the composite state is activated, certain substates are activated.
- Transitions between substates: Within a composite state, substates can transition between each other in response to certain events. These transitions use the same mechanisms as transitions between states.
- Enable and Disable: When a composite state is activated or deactivated, its internal substates are also activated or deactivated respectively.
- Example of transition : Examples of the two types of transitions that can occur in a complex state are:
- Transitions originating from the boundary of a composite state: This type of transition can be executed upon the occurrence of a specific event, regardless of which substate of the composite state it is in.
- Transitions that begin in a specific nested substate: This type of transition is executed in response to the occurrence of an event only when the composite state is in a specific substate.
3. Final State
A final state is a state that represents the end of a particular task or the life cycle of a system or component. Transitioning to this state typically signifies completion of a process or activity; no further state transitions occur.
- Notation of final state : The final state is represented by a small filled circle surrounded by a larger circle. This unique notation is easily identifiable within the diagram and clearly indicates where the execution of the state machine ends.
- The role of the final state
- Indication of completion : Transition to the final state marks the completion of the state machine operation. At this point, the state machine does not react to any further events, and the state machine’s life cycle ends.
- End of operation: When the final state is reached, it indicates that the task or process being handled by the state machine has been completed successfully, or that certain conditions have been met and no further state transitions are required.
- Final state and state : machine design The final state is an important factor when designing a state machine diagram. This allows system engineers to clearly define when the system’s actions are complete and under what conditions the system’s work will be terminated. The end state can also be used as a reference point to evaluate whether the system has achieved its goals.
Transitions: A key element of state machine diagrams
In a state machine diagram, transitions are the key elements that represent changes in the state of a system or component. Transitions play an important role in understanding and predicting the behavior of a system. This section details the transition concept, components, and implementation process.
Basic structure of transitions
A transition represents a movement from a source state (starting point) to a destination state (destination point). This is represented by a solid line with an open arrowhead, and the same applies for self-transitions (where source and target are the same).
Components of a transition
Each transition can contain three optional pieces of information:
- Trigger: An event that initiates a state change. Certain events defined within the system can play this role.
- Guard: This is a condition that determines whether the transition will be executed when a trigger occurs. A guard is expressed as a Boolean expression, and the transition is only executed if this expression is true.
- Effect: This is the action that occurs as a result of the execution of the transition. This indicates specific actions that must be performed during the state change process.
Implementation process of conversion
The transition follows a process from execution to completion that includes the following steps:
- Exit Action of Source State: This is the action of source state that must be executed before transition.
- Transition Effect: This is an action executed during the transition from the source state to the target state.
- Entry Action of the target state: This is the first action executed after entering the target state.
These three steps are considered as atomic processes in which the occurrence of new events cannot interrupt the transition process. This means that once the transition process has started, no other actions can intervene until it is complete.
The importance of transition
Transitions are an essential element in accurately modeling the dynamic behavior of a system. Each transition defines how the system will react and under what conditions, allowing system designers to clearly understand and predict the system’s behavior. State machine diagrams designed through transitions become an important tool for systematically analyzing and verifying the behavior of a system.
Comparison of external and internal conversions
In a state machine diagram, transitions are the key mechanism that represents changes in the state of a system. There are two types of transitions: external and internal, each with different characteristics and purposes. Let’s compare these two types of transitions to see how they can be used in the design and analysis of state machine diagrams.
External conversion
External transitions represent movement from one state to another. This is the most common type of transition, with arrows graphically representing the change between states. External transitions have the following characteristics:
- Source-to-destination transition : An external transition starts in a source state and ends in a destination state, during which the state machine leaves the source state and moves to another state.
- Execution of actions : During the transition, the exit action of the source state, the effect of the transition itself, and the entry action of the target state are executed sequentially.
Internal conversion
An internal transition is when a state machine executes an action in response to an event that occurs within a certain state, but does not leave that state. Internal transitions have the following characteristics:
- Maintenance of state : When an internal transition occurs, the state machine maintains the current state and does not execute any exit or entry operations.
- Run only effects : Internal transitions run only the effects specified in the transition. This is useful for responding to specific conditions or events within a state.
Choosing between external and internal conversion
When designing a state machine diagram, it is important to select and use external and internal transitions appropriately to accurately represent the behavior of the system. External transitions represent explicit movement between states, while internal transitions represent the processing of events within a specific state and can help reduce the complexity of a state machine.
If you are interested in other articles about the basic Knowledge of SysML with EA, please refer to the links below!
[SysML] #1. Understanding SysML Diagrams
[SysML] #2. Understanding SysML Package Diagram
[SysML] #3. Understanding Dependencies of Pkg Diagram
[SysML] #4. How to draw a Pkg Diagram with EA
[SysML] #5. Understanding SysML Requirement Diagram
[SysML] #6. Understanding Relations In Req Diagram
[SysML] #7. How to draw a Req Diagram with EA
[SysML] #8. Understanding SysML UseCase Diagram
[SysML] #9. How to draw a UseCase Diagram with EA
[SysML] #10. Understanding SysML bdd Diagram
[SysML] #11. Understanding SysML ibd Diagram
[SysML] #12. Understanding Part Property of Block
[SysML] #13. Understanding Reference Property of Block
[SysML] #14. Understanding Value Type
[SysML] #15 Understanding Parametric Diagram
[SysML] #16. Understanding Flow Property
[SysML] #17. Understanding Port and Association Block
[SysML] #18. Understanding Behavior of Block
[SysML] #19. Understanding Generalizations
[SysML] #20. Understanding Dependencies, Allocate, Comment
[SysML] #21. Understanding Activity Diagram
[SysML] #22. How to draw a Activity Diagram with EA
[SysML] #23. Seq Diagram LifeLine and Message
[SysML] #24. Seq Diag Constraints Fragment Decompose
[SysML] #25. How to draw a Sequence Diagram with EA
[SysML] #27. Understanding Stm Diagram Event Pseudostate Region