State Diagram
State Diagram
Diagrams and
Modeling
State Machine Diagram
• These diagrams illustrates the interesting
events and states of an object and the
behavior of an object in reaction to an
event.
• The state diagram shows the life cycle of
the object.
• Sometimes it is not possible to show each
and every event in the state diagram.
Events, states and transitions
– Event: significant occurrence of something..
• E.g., customer inserts ATM card.
– State: it is a condition of an object at a moment in
time (between events).
ex waiting for user to enter PIN
authenticating the user
dispensing cash (these states represent the
object is waiting for something or doing something.)
– Transition: a relationship between two states; when
an event occurs, the object moves from the current
state to a related state
ex when a system performs “startup” the transition
from ideal state to active state.
UML State Machine Diagram
• States shown as rounded rectangles.
• Transitions shown as arrows.
• Events shown as labels on transition
arrows.
• Initial pseudo-state automatically
transitions to a particular state on object
instantiation.
• Events with no corresponding transitions
are ignored.
State machine diagram for a telephone
Transition Actions and Guards
• A transition can cause an action to fire.
– In software implementation, a method of the
class of the state machine is invoked.
• A transition may have a conditional guard.
– The transition occurs only if the test passes.
Transition action and guard notation
transition action
on hook
guard condition
Nested States
• A state may be represented as nested
substates.
– In UML, substates are shown by nesting them
in a superstate box.
• A substate inherits the transitions of its
superstate.
– Allows succinct state machine diagrams.
Nested states
Active
[valid subscriber]
Idle
PlayingDialTone Talking
on h
ook
complete
Dialing Connecting
State-Independent
enterItem
endSale
makeCreditPayment
AuthorizingPayment makeCheckPayment
More notations
Transition
action
Guard
condition