Unit 5 (D)
Unit 5 (D)
A state diagram is a graph whose nodes are states and whose directed arcs are transitions
between states.
1
Components of state diagram
Initial State
A solid circle with an outgoing arrow shows the initial state.
Final State OR
A bull’s eye – a solid circle surrounded by a hollow circle/encircled X shows the termination
point.
State
State
Drawn as a rounded box containing the name of the state.
State names must be unique within the scope of the state diagram.
Our convention is to list state name in boldface, center the name near the top of the box, and
capitalize the first letter.
event(attribs) [condition]
Transition/Event
Drawn as a line from the origin state to the target state.
An arrowhead points to the target state.
2
Components of state diagram
event(attribs) [condition]
Guard condition
A guard condition is a Boolean expression that must be true in order for a transition to occur.
A guarded transition fires when its event occurs.
Optionally listed in square brackets after an event.
3
How to draw a state diagram
Step 1: Identify the important objects.
Step 2: Identify the possible states in which the object can exist.
Step 3: Identify the initial state and the final terminating states.
Step 4: Label the events which trigger these transitions.
4
State diagram for library management system
Identify the important objects
Book
CD/DVD
News Paper
Librarian
Member
Identify the states of Book’s Object
Available
Issue
Return
Renew
Identify the events / transition
Book issued to user
Submit the book
Request to issue same book
Completion of exam / end of the Semester
5
State diagram of book
Book
Book re-issue
Return Renew
6
Example: State diagram of Bank Automated Teller Machine (ATM)
This is an example of UML behavioral state diagram showing Bank Automated Teller Machine
(ATM) top level state machine.
ATM is initially turned off. After the power is turned on, ATM performs startup action and
enters Self Test state.
If the test fails, ATM goes into Out of Service state, otherwise there is trigger less transition to
the Idle state. In this state ATM waits for customer interaction.
The ATM state changes from Idle to Serving Customer when the customer inserts banking or
credit card in the ATM's card reader.
On entering the Serving Customer state, the entry action readCard is performed.
Note, that transition from Serving Customer state back to the Idle state could be triggered by
cancel event as the customer could cancel transaction at any time.
Serving Customer state is a composite state with sequential substates Customer
Authentication, Selecting Transaction and Transaction.
7
State diagram of Bank Automated Teller Machine (ATM)
Bank ATM
turn on /
startup
successfully failure
Self Test
turn on /
restart
failure
service Out of
Idle Maintenance Service
service
cancel
serving customer
Customer Selecting
Transaction
Authentication Transaction
8
Example: State diagram of Online Order
Here is just another example of how an online ordering system might look like.
On the event of an order being received, we transit from initial state to Unprocessed order
state.
The unprocessed order is checked.
If the order is rejected, we transit to the Rejected order state.
If the order is accepted and we have the items available, we transit to the fulfilled order state.
However if the items are not available, we transit to the Pending order state.
After the order is fulfilled, we transit to the final state. In this example, we merge the two states
i.e. Fulfilled order and Rejected order into one final state.
9
State diagram of Online Order
Order
order received
Unprocessed
Rejected Accepted
10