2014年2月27日星期四

Statechart Diagram of UML Modelling

1.Brief introduction
State diagram is mainly used in describing the dynamic behavior of an object during its existence, performance for the sequence of States that experienced by an object, cause a events of State transition (Event), and the action triggered by State transition(Action). Generally we can use a state machine for modeling the life cycle of an object, state diagrams are used to display the state machine (State Machine Diagram), focusing on the control flow of describing state diagram.

The sample below, showed the state diagram of Door, caused the transfer event, and accompanied by the state transition actions ( action ).

Status include Opened,Closed,Locked.
Events include Open、Close, Unlock.

Notice:

A. Not all the events will trigger state transition, for example when the door is opened, the event locked will not happen.

B. There is guard condition in transition, for example only doorWay->isEmpty, the event would happen.

2.State Diagram Elements

a. States
States refers to a condition or situation in the object's life cycle, during which objects that meet certain criteria, to perform certain activities for certain events. All the objects have State, the State is the results of a series of activities, when an event occurs, the states will change .

State represented by a rounded rectangle



Initial and Final States


b. Transitions

Transition is the connection between two states, indicates the object performs certain actions in the source state, and enter the target state when meeting the condition that certain events occurs&Guard condition.


Trigger: trigged the transitions, can be a signal, event, condition changes and time expression.

Guard Condition: whe the Guard Condition are net, the transitons of events will happen. Effect: the results of object states transfer.

c. State Actions

In last example, the result is displayed in the transfer line, if the object state has many transitions and each transition results in same, then the result(Effect) would be netter to be displayed in the Target State, thus to define the Entry Action and Exit Action.



d. Self-Transitions


After 2 second, execute the event of Poll input,transfer to it’s own state【Waiting】

e. Compound States

The state nested in another State named sub-State (sub-State), a State with sub-state called the combined state (Compound States). The following figure, the "Check PIN" is a Compound State, "Enter PIN" is the sub one.


f. Entry Point

The initialization is not executed for some reason, but directly enter in the state【Ready】 through a point, this point is named Entry Point.


g. Exit Point


h. History States

History State is the Pseudostate, it is used to remember the sub-sate when exiting form a compound state, when enter the compound state again, can directly enter in the sub-sate, rather than start from the initial state.


In this diagram, the normal state order is:【Washing】- >【Rinsing】->【Spinning】。

If power cut, then exit from Ringsing, the washing machine stop work and enter in the state PowerOff, when power restored, directly enter in the state Running.

i. Concurrent Regions

State diagrams can be divided into regions, regions include exit or the current execution sub-state. That means Compound State can be achieved simultaneously at more than one State.The Following diagram, Brake system, enter simultaneously into the state of front brakes "Applying Front Brakes", and the rear brake, "Applying Rear Brakes".


3.State Diagram Example Analysis



4.Summary

The main point of State Diagram is to describle the object transitions between different states. The basic elements of State Diagram include:States, Transitions, State Actions, Self-Transitions, Compound States, Entry Point, Exit Point, History States, Concurrent Regions. The events in the stated are sorted in Call, Change, Time, Signal.

没有评论:

发表评论