UML State diagrams and activity diagrams

Source: Internet
Author: User

UML State diagrams and activity diagrams

The Unified Modeling Language UML (Unified Modeling Language) is a non-patented third-generation modeling and specification language. UML is an open approach for explaining, visualizing, building, and writing an open approach to an object-oriented, software-dense system of artifacts. UML presents a series of best practices that are validated for modeling large-scale, complex systems, especially at the software architecture level.

UML defines 5 classes, 10 model diagrams:


1. Use case diagram: Describe the system function from the user's perspective and refer to the operator of each function.
2. Static diagram: Including class diagram, Package diagram, object graph.
Class diagrams: Describing the static structure of classes in a system
Package diagram: A package and class that represents the relationship between packages and packages, package diagrams describes the hierarchical structure of the system
Object graph: An instance of a class diagram
3. Behavior diagram: Describe the exchange relationship between the system dynamic model and the object composition. Include state and activity diagrams
Activity diagram: Describes the workflow of a business implementation use case
State diagram: Is a description of state-to-state control flow, often used for dynamic characterization modeling
4. Interaction diagram: Describe the interaction between objects
Sequence diagrams: Dynamic relationships between objects, emphasizing the order in which objects send messages, and displaying interactions between objects
Collaboration diagram: Describe the assistance relationship between objects
5. Implementation diagram:
Configuration diagram: Define the physical architecture of hardware and software in the system

The goal of UML is to describe any type of system in object-oriented graph, which has a wide range of applications. One of the most common is the model of a software system, but it can also be used to describe systems in non-software areas, such as mechanical systems, enterprise organizations or business processes, as well as information systems dealing with complex data, industrial systems or industrial processes with real-time requirements. In summary, UML is a common standard modeling language that can model any system that has static structure and dynamic behavior.

In addition, UML is suitable for different stages of system development from requirements specification to test after system completion. In the requirements analysis phase, you can use use cases to capture user requirements. Use case modeling to describe external roles that are of interest to the system and their functional requirements for systems (use cases). The analysis phase focuses on the main concepts in the problem domain (such as abstractions, classes, objects, etc.) and mechanisms, needs to identify these classes and their relationships with each other, and describes them with UML class diagrams. To implement use cases, the classes need to collaborate, which can be described using a UML dynamic model. In the analysis phase, only the object of the problem domain (the real-world concept) is modeled, regardless of the class that defines the technical details in the software system (such as classes that handle issues such as user interfaces, databases, communications, and parallelism). These technical details are introduced in the design phase, so the design phase provides a more detailed specification for the construction phase.

Programming (construction) is a separate phase whose task is to translate classes from the design phase into actual code in an object-oriented programming language. When building analysis and design models with UML, it is necessary to avoid considering transforming the model into a specific programming language. Because in the early stages, the model is merely a tool to understand and analyze the structure of the system, premature consideration of the coding problem is very detrimental to the establishment of a simple and correct model.

The UML model can also be used as a basis for the testing phase. Systems typically require unit testing, integration testing, system testing, and acceptance testing. Different test teams use different UML diagrams as a test basis: Unit tests use class diagrams and class specifications, integration tests use part diagrams and collaboration diagrams, system tests use use case diagrams to verify the behavior of the system, and acceptance tests are performed by the user to verify that the results of the system tests meet the requirements identified during the analysis phase.

In short, the standard modeling language UML applies to object-oriented technology to describe any type of system, and is suitable for different stages of system development, from requirements specification to test and maintenance after the system is completed.

This article mainly introduces the state diagram and activity diagram.

I. State diagram


A state is a condition or condition that occurs during the life of an object, during which the object satisfies certain conditions, performs certain activities, or waits for certain events. All objects have a state, and the state is the result of an object performing a series of activities, and when an event occurs, the state of the object changes.

State diagram (statechart diagram):
Used to describe all possible states of a particular object, as well as transitions and changes between states caused by the occurrence of various events.
Not all classes need to draw state diagrams, have a clear sense of state, and behave differently in different states in order to draw a state diagram. As follows
A state diagram of a machine

As another example, the status diagram of CD player

1. Status
A state has the following parts: The state name, the Enter/exit action (Entry/exit action), the internal transfer (internal transttion), the Child State (substate), and the delay event (dferred events).
States can be subdivided into different types, such as initial state, final state, intermediate state, combined state, historical state, etc. A state diagram can have only one initial state, but the end state may have one or more, or no end state.
The middle state consists of two regions: the Name field and the internal transfer domain. Where the internal transfer domain is optional.

The horizontal line above is the Name field, and the following is the conversion domain (optional).

Ntry/turnon: When in this state, do turn on the light action.
do/blinkfivetimes: When in this state, the lamp blinks 5 times. A do activity is an activity that appears only in the state and cannot be attached to a transition.
Event Poweroff/powersupplyself: when the power-off event occurs, use your own power supply.
Exit/turnoff: When the state is turned off, do the light action.
Event Selftest/defer: When the SelfTest event occurs, the object will delay the response and be processed in another state, using the defer specific action to express the delay.

2. Elements of a state diagram


ellipse or Rounded rectangle: represents a state of an object, inside the ellipse fills in a state name
Arrow: indicates that the state from the arrow can be converted to the state pointed to by the Arrow
event: The cause of the state transition. The event name can be marked above the arrow line
condition: Add square brackets after event name, write state transition condition in parentheses
Solid Circle: Initial state
Inner Solid Concentric circle: Final State

3. Type of Status

① by State process:

② states that contain sub-states are called grouped or nested states

A combined state can be decomposed into a concurrent sub-state by using the and relationship, or by decomposing the "or" relationship into a mutually exclusive order sub-state. Two methods of representation:
Order sub-state
If a child state of a constituent state corresponds to an object that can be in only one sub-state at any point in its lifetime, that is, multiple sub-states are mutually exclusive and cannot exist simultaneously, this seed state is called the order sub-state.


Concurrency sub-state
Sometimes the combined state has two or more concurrent sub-state machines, at which point the sub-state of the constituent state is the concurrency sub-state.

Historical State is a pseudo state, the purpose of which is to remember the sub-state when exiting from the combined state, when it enters the combined state, it can go directly into the sub-state, instead of starting from the initial state of the combined state.

Shallow (shallow) historical state, remembering only the history of the outermost combined state.


The history of the combined state of any depth can be remembered in deep (deeper) historical state.

The CD player,running state is interrupted to the power on state, and then goes back to the running state, hoping to enter the historical state directly

4. Transfer (Transition)
A transition is a relationship between two states that represents an object that executes an action in the current state and enters a successor state when a particular event occurs or when a particular condition is satisfied. Each transfer allows only one event to be triggered, and an event allows only one action.

Five Elements of ① transfer (note format)

Format: Event (parameter) [Conditional]/action
? source State
? target status
? Trigger Event
-If the arrow does not have any event names, it is an automatic conversion that is triggered automatically when the activity associated with the source state is completed.
? Guardianship conditions
? action

Types of ② Conversions

Internal transfer: Does not cause a transition of state change, does not perform entry and exit actions


External transfer
Self-transfer

5. Events (Event)
An event is a specification of a meaningful thing that occupies a certain place in time and space. The transition of the event-triggered state.


Four main types of events:
? Signal Events
? Invoke Event
? Change events
? Time Events

① Signal Signer Event
The communication between the objects is achieved by sending signals and receiving signals. A signal is an asynchronous mechanism. In the computer, the mouse and keyboard actions belong to this type of event. For a signal, the object generally has a corresponding event handler, such as Onmouseclick () and so on.

② Call Event
Represents the dispatch of an operation. An object requests an operation that invokes another object
The signal is an asynchronous event, and the invocation event is generally synchronous. That is, when an object invokes the operation of another object, the control is transferred from the sender to the receiver, the event triggers the transformation, the receiver transitions to a new state after the operation is completed, and the control is returned to the sender.

③ Change Event
With a keyword when, followed by a Boolean expression
When (temperature>120)/alerm ()
The intent of a change event is to test the expression frequently, as long as the expression is changed from false to true.

Note: The difference between change events and guardianship conditions

④ Time Event
A time event is an event caused by an absolute time or something that occurs within a certain time interval.
For example, to arrive at a certain time or go through a period. denoted by the keyword when or after.

6. State diagram Modeling Techniques

Modeling steps:
① find a class that is suitable for describing its behavior with a model.
② determines the possible state of an object.
③ determines the event that caused the state transition.
④ determines the corresponding action of the object execution when the transformation occurs.
⑤ the results of modeling are refined and refined accordingly.

Two. Activity diagram

1. The concept of activity diagrams
Activity diagram is one of the dynamic views of UML, which is used to describe the process of changing the activity of a thing or an object. An activity diagram can be thought of as a special form of a state diagram. The peculiarity is that when an activity in an activity diagram ends, it will immediately enter the next activity without the need for an event-triggered activity to move.

The activity diagram is used to describe the workflow and concurrency behavior of the system. Activity diagrams are designed to simplify the work steps that describe a process or operation. For example, you can model the development process of a software using activity diagrams, and you can model operations such as the number of nth numbers in a fibnacci sequence.

Activity diagram Example:

2. Composition elements of the activity diagram:


? Activities (activity)
? Action Flow
? Branching (Branch) and merging (merge)
? Fork (fork) and Convergence (Join)
? Swimlane (Swimlane)
? Object flow

3. Activities

Activity represents the execution of a task in a process, which can represent the execution of a statement during an algorithm. An activity is represented in an activity diagram as a non-atomic execution process consisting of a series of actions.


Action status (Action State)
Active status (activity State)

① Action State

An action state is a state that performs an atomic, non-disruptive action, and then turns to another state by completing the transition after the action is completed.
The action state is represented by a smooth rounded rectangle, and the actions represented by the action state are written inside the rounded rectangle.

② activity Status

The active state is decomposed, not atomic, and its work needs to be completed in a certain amount of time.
The action state can be regarded as a special case of active state.
The representation icon for the active state is also a smooth rounded rectangle, and information such as the entry action and exit action can be given in the icon.

4. Action Flow

The flow of transitions between all action states is called an action flow.
The conversion of an activity diagram does not require a specific event to be fired, and an action state is automatically converted to another state after execution.
The conversion of the activity diagram is represented by a straight line with arrows.
A conditional limit conversion is available.

5. Branching and merging

A branch is typically used to represent the conditional behavior of an object class.
Conditional behavior is expressed by branching and merging.
A branch has one-in-transition and two conditional out conversions, and the conditions for the transitions should be mutually exclusive.
A merge has two conditional in transitions and one out transform, and the merge represents the end of the conditional behavior starting from the corresponding branch.

6. Bifurcation and convergence

Forks are used to divide the action flow into two or more concurrently running branches, and the convergence is used to synchronize the concurrent branches to achieve a common purpose of accomplishing a transaction.
Forks can be used to describe concurrent threads.
Convergence represents the synchronization of two or more concurrent control flows, and the control can continue down after all control flows have reached the convergence point.

7. Swimlane

The swimlane divides the activity in the activity diagram into groups and assigns each group to the business organization that is responsible for the group of activities, usually the object.
The Swimlane distinguishes between the objects responsible for the activity and clearly indicates which objects are being carried out by which activities.
Each activity can only explicitly belong to one swimlane.
The lane is drawn with a vertical solid line, and the area separated by the vertical line is the swimlane. Above the swimlane you can give the name of the Swimlane or the name of the object (object class) that is responsible for all the activities within the swimlane.
Lanes have no order, and activities in different lanes can be performed sequentially or concurrently, and the motion and object flows allow traversal of the divider line.

8. Decomposition of activities

An activity can be divided into several actions or sub-activities, and these actions and sub-activities themselves can be composed of an activity diagram.
An activity that does not contain an inline activity or action is called a simple activity, and an activity that has a number of activities or actions nested
For the combined activity, the combined activity has its own name and the corresponding child activity diagram.

An activity that contains child activities is similar to the combined state of nested sub-states and is conceptually relatively uniform.

9. Use of activity diagrams

? Modeling the System workflow
Workflow: is a well-defined sequence of actions that, when executed, produces an observable value, or an object that produces an individual or entity.
? Modeling of engineering organization processes
? Modeling algorithmic processes

① Modeling System Workflow


② Modeling of engineering Organization process


③ Modeling of algorithmic processes

10. Activity Map Modeling Technology


① identifies the class or object to which the workflow is to be described.
② determines the initial and terminating states of a workflow and clarifies the boundaries of the workflow.
③ model the action state or activity State.
④ model the action flow.
⑤ model the object flow.
⑥ refinement and refinement of the established model

Three. Comparison of activity diagram and state diagram

1. The same point of the activity diagram and the state diagram :
Are modeled on the dynamic behavior of the system.

2. The difference between the activity diagram and the state diagram:
① describe objects differently


State diagram: describes the transition between the state of an object and its state;
activity diagram: describes the control flow from activity to activity.


② different use occasions


State diagram: describes the changes in the behavior state of an object during its life;
activity diagram: describes the process change of the procedure.

Four. UML Drawing Professional Tool IBM.Rational.Rose.Enterprise

Attached: ibm.rational.rose.enterprise.v7.0 cracked version download

Finish

Reprint please specify the reproduced words, mark the original author and the original post address!

UML State diagrams and activity diagrams

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.