Software Engineering - State Transition Diagram Notes + Examples

1. Why use state transition diagram (STD)

When formulating requirements analysis tasks, it is necessary to write software requirements specifications, which may use several main models of structural analysis methods, among which the behavior model of the software system (that is, the state transition diagram) should be established.

2. What is STD

In order to reflect the changing law of things, a dynamic model of the system should be established in demand analysis.
The state transition diagram represents the behavior of the system by depicting the state of the system and the events that cause the state transition of the system.
A state transition diagram also specifies what actions the system will take (eg, process data) as a result of certain events.

Three, state, event

A state is an observable system behavior pattern that specifies how the system responds to events, either by doing a (series of) actions, or just changing the state of the system itself, or both.
An event is something that happens at a specific moment, an abstraction of an external event that causes the system to act or transition from one state to another. If the mouse is moved or clicked, the internal clock indicates that a specified period of time has elapsed.

4. Symbols

The concepts introduced below are somewhat abstract (hey, he moved them according to the script), and you can experience the actual usage from actual examples

Initial state : solid circle
Final state : concentric
circle Intermediate state : rounded rectangle, which can be divided into upper, middle and lower parts by horizontal lines, the upper part (required) is the name of the state, the middle part (optional) is the name of the state variable and value, the lower part (optional) is the activity table (the syntax will be explained below) the
syntax format of the activity table: event name/action expression, the event name often uses the following three standard events: the entry event specifies the action to enter the state; The exit event specifies the action to exit the state, and the do event specifies the action in the state. Action expressions describe specific actions that should be performed.
State transition : A line with an arrow. The state change is usually triggered by an event. The event expression that triggers the transition should be marked (the syntax will be explained below). If it is not marked, it means that the internal activities in the source state will automatically trigger the transition.
Event expression syntax format: event description [Boolean expression]/action expression

Note: The brackets in [] means optional

5. Practical examples

example one

Telephone system state diagram: when no one is calling, the phone is in idle state, and someone picks up the handset and enters the dialing state. After reaching this state, the phone behavior is to ring the dial tone and count the time; if the person who picks up the handset does not want to call, put the handset down (hang up) and return to the idle state; if you pick up the phone for a long time without dialing (timeout), it will enter the timeout state...
insert image description here

Example 2

The working process of the copier is roughly as follows: it is in the idle state when it does not receive a copy order, and enters the copy state once it receives a copy order, and returns to the idle state after completing the work specified by a copy order, waiting for the next copy order
; If there is no paper when ordering, it will enter the paper-out state, issue a warning, wait for paper loading, and enter the idle state after the paper is full, ready to receive copy commands; if a paper jam occurs during copying, it will enter the paper jam state, issue a warning and wait for
maintenance Personnel come to troubleshoot, and return to idle after troubleshooting. Use a state transition diagram to describe the behavior of the copier.
insert image description here

Guess you like

Origin blog.csdn.net/weixin_52323239/article/details/130368163