State Machine Diagram

State Machine Diagram State Machine Diagram „ A State Machine Diagram „ models d l the h behavior b h i off a single i l object bj „ specifies the ...
Author: Adela Stanley
2 downloads 0 Views 112KB Size
State Machine Diagram

State Machine Diagram „

A State Machine Diagram „ models d l the h behavior b h i off a single i l object bj „ specifies the sequence of events that an object bj t goes through th h during d i its it lifetime lif ti in i response to events

A State Machine Diagram

„

The door can be in one of 3 States: Opened, Closed, Locked

State „ „ „ „ „

A state is a specific situation of an element during its lifecycle Define the states for your elements The current state of an element is called its active state, and the element is said to be "in" in that state. state There are various types of states, including simple, initial, and final states. In the UML UML, a simple state is shown as a rectangle with rounded corners and labeled with the name of the state or a description of the situation of the element

Initial State and Final State „ „ „

„

An initial state indicates the state of an element when it is created In the UML, an initial state is shown using a small solid filled circle A final state indicates the state of an element when it is destroyed. In the UML, a final state is shown using a circle surrounding a small solid filled circle (a bull's eye) A state diagram may have only one initial state, but mayy have anyy number of final states

Transition „

The complete description of transition consists of three parts: Trigger [Guard] / Effect

Transition Description „

„

„

"Trigger" is the cause of the transition, which could be a signal, g , an event,, a change g in some condition, or the passage of time "Guard" is a condition which must be true in order for the trigger to cause the transition "Effect" Effect is an action which will be invoked directly on the object that owns the state machine as a result of the transition.

State Action •If the target state had many transitions arriving at it, and each transition had the same effect associated with it, it would be better to associate the effect with the target state rather than the transitions „

This can be done by defining an entry action for the state. The diagram d ag a below be o shows s o s a state with an entry action and an exit action.

Self Transition „

A state can have a transition that returns to itself

Compound States „

A state machine diagram may include sub submachine d ag a s diagrams

Hiding SubMachine „

SubMachine will be shown in a separate diagram

Entry Point „

„

Sometimes yyou won’t want to enter a sub-machine at the normal initial state For example, p , in the following g sub-machine it would be normal to begin in the "Initializing" state, but if for some reason it wasn’t necessary to perform the initialization, it would be possible ibl to t begin b i in i the th "Ready" state by transitioning to the named entry point.

Higher Level

Lower Level in “Performing Activity” State

Exit Point

„

„

In a similar manner to entry points points, it is possible to have named alternative exit points The following diagram gives an example where the state executed after the main processing state depends on which route is used to transition out of the state.

Choice Pseudo State

„

„

A choice pseudo pseudo-state state is shown as a diamond with one transition arriving and two or more transitions leaving The above diagram shows that whichever state is arrived at, after the choice pseudo pseudo-state, state is dependent on the message format selected during execution of the previous state.

Junction Pseudo-State

„ „

„ „

Junction pseudo pseudo-states states are used to chain together multiple transitions A single junction can have one or more incoming, and one or more outgoing, transitions; a guard can be applied to each transition Junctions are semantic-free A junction which splits an incoming transition into multiple outgoing transitions realizes a static conditional branch, as opposed to a choice pseudo-state which realizes a dynamic conditional branch.

Terminate Pseudo-State

„

„

Entering a terminate pseudo-state indicates that the lifeline of the state machine has ended A terminate pseudo-state is notated as a cross.

History States

„

„

A history state is used to remember the previous state of a state machine when it was interrupted The above diagram illustrates the use of history states. The h example l is a state machine h belonging b l to a washing machine.

Concurrent Regions

„

„

„

A state may be divided into regions containing sub-states that exist and execute concurrently The example above shows that within the state "Applying Brakes", the front and rear brakes will be operating simultaneously and independently Notice the use of fork and join pseudo-states, rather than choice and merge pseudo-states These symbols are used to synchronize the concurrent threads.