What Is State Machine Diagram?
What Is State Machine Diagram?
What/
HOME isSUPPORT
State Machine
/ WHAT ISDiagram?
STATE MACHINE DIAGRAM?
Related Links
The behavior of an entity is not only a direct consequence of its inputs, but it also depends on its preceding
state. The past history of an entity can best be modeled by a !nite state machine diagram or traditionally
called automata. UML State Machine Diagrams (or sometimes referred to as state diagram, state machine or
state chart) show the di"erent states of an entity. State machine diagrams can also show how an entity
responds to various events by changing from one state to another. State machine diagram is a UML diagram
used to model the dynamic nature of a system.
Free Download
For example:
Consider you have $100,000 in a bank account. The behavior of the withdraw function would be: balance :=
balance - withdrawAmount; provided that the balance after the withdrawal is not less than $0; this is true
regardless of how many times you have withdrawn money from the bank. In such situations, the withdrawals
do not a"ect the abstraction of the attribute values, and hence the gross behavior of the object remains
unchanged.
However, if the account balance would become negative after a withdrawal, the behavior of the withdraw
function would be quite di"erent. This is because the state of the bank account is changed from positive to
negative; in technical jargon, a transition from the positive state to the negative state is !red.
The abstraction of the attribute value is a property of the system, rather than a globally applicable rule. For
example, if the bank changes the business rule to allow the bank balance to be overdrawn by 2000 dollars, the
state of the bank account will be rede!ned with condition that the balance after withdrawal must not be less
than $2000 in de!cit.
Note That:
A state machine diagram describes all events (and states and transitions for a single object)
A sequence diagram describes the events for a single interaction across all objects involved
What is a State?
Rumbaugh de!nes that:
"A state is an abstraction of the attribute values and links of an object. Sets of values are grouped together
into a state according to properties that a"ect the gross behavior of the object."
State Notation
A state is often associated with an abstraction of attribute values of an entity satisfying some condition(s).
An entity changes its state not only as a direct consequence of the current input, but it is also dependent on
some past history of its inputs.
State
A state is a constraint or a situation in the life cycle of an object, in which a constraint holds, the object
executes an activity or waits for an event.
Example:
Characteristics of State
State represent the conditions of objects at certain points in time.
A point in the lifecycle of a model element that satis!es some condition, where some particular action is
being performed or where some event is waited
The initial state of a state machine diagram, known as an initial pseudo-state, is indicated with a solid circle.
A transition from this state will show the !rst real state
The "nal state of a state machine diagram is shown as concentric circles. An open loop state machine
represents an object that may terminate before the system terminates, while a closed loop state machine
diagram does not have a !nal state; if it is the case, then the object lives until the entire system terminates.
Example:
Events
An event signature is described as Event-name (comma-separated-parameter-list). Events appear in the
internal transition compartment of a state or on a transition between states. An event may be one of four
types:
3. Time event - a time event occurs after a speci!ed time has elapsed
Characteristics of Events
Represents incidents that cause objects to transition from one state to another.
Internal or External Events trigger some activity that changes the state of the system and of some of its
parts
Events pass information, which is elaborated by Objects operations. Objects realize Events
Design involves examining events in a state machine diagram and considering how those events will be
supported by system objects
Transition
Transition lines depict the movement from one state to another. Each transition line is labeled with the event
that causes the transition.
Viewing a system as a set of states and transitions between states is very useful for describing complex
behaviors
2. An event occurs
3. An action is performed
Multiple transitions occur either when di"erent events result in a state terminating or when there are guard
conditions on the transitions
Actions
Action is an executable atomic computation, which includes operation calls, the creation or destruction of
another object, or the sending of a signal to an object. An action is associated with transitions and during
which an action is not interruptible - e.g., entry, exit
Activity
Activity is associated with states, which is a non-atomic or ongoing computation. Activity may run to
completion or continue inde!nitely. An Activity will be terminated by an event that causes a transition from the
state in which the activity is de!ned
States can have a second compartment that contains actions or activities performed while an entity is in a
given state
Five triggers for actions: On Entry, Do, On Event, On Exit, and Include
An activity captures complex behavior that may run for a long duration - An activity may be interrupted by
events, in which case it does not complete occur when an object arrives in a state.
Entry Action executed on entry into state with the notation: Entry / action
Exit Action executed on exit from state with the notation: Exit / action
Note:
1. This state machine diagram shows the state of an object myBkCopy from a BookCopy class
2. Entry action : any action that is marked as linked to the entry action is executed whenever the
given state is entered via a transition
3. Exit action : any action that is marked as linked to the exit action is executed whenever the
state is left via a transition
Substates
A simple state is one which has no substructure. A state which has substates (nested states) is called a
composite state. Substates may be nested to any level. A nested state machine may have at most one initial
state and one !nal state. Substates are used to simplify complex #at state machines by showing that some
states are only possible within a particular context (the enclosing state).
State Machine Diagrams are often used for deriving testing cases, here is a list of possible test ideas:
History States
Unless otherwise speci!ed, when a transition enters a composite state, the action of the nested state
machine starts over again at the initial state (unless the transition targets a substate directly). History states
allow the state machine to re-enter the last substate that was active prior to leaving the composite state. An
example of history state usage is presented in the !gure below.
Concurrent State
As mentioned above, states in state machine diagrams can be nested. Related states can be grouped together
into a single composite state. Nesting states inside others is necessary when an activity involves concurrent
sub-activities. The following state machine diagram models an auction with two concurrent substates:
processing the bid and authorizing the payment limit.
In this example, the state machine !rst entering the Auction requires a fork at the start into two separate start
threads. Each substate has an exit state to mark the end of the thread. Unless there is an abnormal exit
(Canceled or Rejected), the exit from the composite state occurs when both substates have exited.
Free Download
Related Links