UML (6) -- state diagram

Source: Internet
Author: User

A state chart is a modeling of System Dynamics. It describes the dynamic behavior of an object over time by creating a life cycle model of a Class Object.

A status chart is used to describe the behavior of an instance of a model element. It is used to describe the status and action sequence and can display the state owned by an object, it can also explain how events affect these states over time.

State Machine

A state machine is a device that records the state at a given time. It changes its status or triggers an action for each given change based on different inputs. In UML, a state machine is composed of various States of an object and the transition of these states connected. It is a graph showing the transition between States and States. In an object-oriented software system, an object will inevitably go through the entire process from initial creation to final extinction. This process is the object lifecycle. Obviously, an object cannot be completely isolated within its lifecycle. It will accept messages to change itself or send messages to affect other objects. A state machine is used to describe the sequence of states that an object has experienced in responding to events in its lifecycle and its response to these events. In the context of a state machine, an event is triggered once, and each excitation can trigger a state transition.

In UML, state machines are often used to model the dynamic behavior of model elements, that is, to model the event-driven aspects of system behavior. It is always a local view of an object, collaboration, or use case, and is suitable for modeling details.

Status chart

A state chart is essentially a state machine, a projection of elements in a state machine, or a special case of a state machine.

Function of status chart

A state chart is a dynamic modeling of the system. It is suitable for describing the transition between various States and States of objects spanning multiple use cases in their lifecycles. Objects can be classes, interfaces, components, and nodes.

The status chart describes the transition sequence between States. The event execution sequence can be obtained through the state transition sequence. The event sequence can avoid the event error sequence during development; the status chart describes the events that must be triggered during state conversion, monitoring conditions, actions, and other factors that affect the conversion, so as to avoid the intervention of illegal events in the program; the status chart describes the branches of a Workflow Based on different conditions.

Status chart Composition

The status chart starts from the initial state, indicating the state machine, an ending state, indicating the End of the state machine, and element status, conversion, and determination. Status conversion is triggered by an event, and the transition between States is connected by the conversion arrow.

(1) Status

A State is used to model various conditions of an object in its lifecycle. An object is always maintained for a limited period of time. The status is represented by a rounded rectangle,

Status describes a time period in the lifecycle of a Class Object. A State is generally a set of attribute values of objects of a given class. The status can be divided into simple status and composition status. In addition, the status also includes status name, internal activity, internal conversion, entry action, exit action, and historical status.

The status name is used to distinguish it from other statuses. The name is usually placed at the top of the status chart.

Internal activity. When the activity enters the status, the activity starts after the activity is completed. If the activity ends, the status is completed, and a switch from this status is triggered, otherwise, the status will wait for the switch to be triggered to change the status.

Internal conversion, the state may contain a series of internal transformations. The internal conversion is only in the source State without the target State, so the internal conversion result does not change the State itself. The condition for initiating an internal conversion is the same as that for initiating an external conversion. However, in the ordered area, each event only fires one conversion, and the internal conversion has a higher priority than the external conversion. Unlike self-conversion, self-conversion is an external conversion, which can force exit from the nested state, but internal conversion cannot.

The entry and exit actions are dependent on the switch between the entry and exit. By encapsulating the status, you can use it when you do not know the internal status of the status.

Historical Status, which may contain historical states. It is a pseudo State that describes the substates of a previous state. It is represented by a circle with H.

Composition status: the status with substates nested inside. Multiple Sub-States are mutually exclusive and cannot exist at the same time. The composition state is called the sequential composition state. There are two or more concurrent sub-states, and the composition state is called the concurrency composition state.

(2) Conversion

The conversion is represented by a line segment with an arrow. the arrow points to the target State and the other end to the source State. The switch can mark options related to this status: events, monitoring conditions, and actions. If no conversion event is marked, the conversion is automatically performed.

External conversion is the most common conversion. It is represented by an arrow line segment from the source State to the target State.

Internal Conversion: the internal conversion has no target State, only the source State, and does not stimulate the entry and exit actions. Therefore, the results of the internal conversion do not change the original state.

Complete Conversion: it is not explicitly indicated that the conversion of the trigger event is caused by the completion of activities in the status.

Composite conversion: it is a combination of simple conversions through branch and merge. Hollow diamond represents judgment, and can also represent merging.

Monitoring condition: A monitoring condition is a Boolean expression that must be met to trigger conversion. When a trigger event is triggered, the monitoring condition is assigned a value. If the value is true, the conversion can be stimulated, and vice versa. If the conversion does not have a monitoring condition, the monitoring condition is considered true. Once a trigger event occurs, the conversion is activated. The value of the monitoring condition is calculated only once when the event is processed. Complex monitoring conditions can be divided into a series of simple monitoring conditions, which are used as the branches of trigger events or monitoring conditions. Each branch is a separate conversion.

Trigger event: an event that can cause state conversion. It can be a signal, call, or time period. The conversion of trigger events is called the end conversion.

Action: it is usually a brief computing process or a set of executable statements. Actions are atomic. Its execution is independent. Once it starts, it must be completed. Actions can be divided into assignment, call, creation, destruction, return, sending, termination, and non-interruption.

(3) Determination

Different conversions are performed based on different judgment results, that is, the workflow occurs branch at the judgment according to the value of the monitoring condition. It is determined to be represented by a hollow diamond. Generally, it is determined that there is one transfer in and two transfers. Different Branch conversions can be triggered Based on the authenticity of the monitoring conditions.

(4) Synchronization

Synchronization is represented by a line segment to describe the branch and convergence of concurrent workflows. Concurrent branch means that a separate workflow is divided into two or more workflows, and the branch workflow is executed in parallel. Concurrent confluence means that two or more concurrent workflows are synchronized, indicates that the workflow that is completed first must wait until all the workflows arrive before continuing to execute the following workflow. Different from determination, branches are parallel.

(5) Event

In a state machine, an event can trigger a state change. It can be divided into signal events, call events, change events, and time events.

 

Example:


 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.