0% found this document useful (0 votes)
58 views10 pages

Unit 5 (D)

A state diagram is a graph that models the different states an object can be in, and the transitions between those states caused by events. It contains states as nodes, transitions between states as directed arcs, and usually shows an initial state and final states. Key components are states, transitions, events, and sometimes guard conditions. To create a state diagram, important objects and their possible states are identified, along with initial/final states and triggering events between states. Examples shown include the states of a book in a library system and an ATM machine.

Uploaded by

meet 0102
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
58 views10 pages

Unit 5 (D)

A state diagram is a graph that models the different states an object can be in, and the transitions between those states caused by events. It contains states as nodes, transitions between states as directed arcs, and usually shows an initial state and final states. Key components are states, transitions, events, and sometimes guard conditions. To create a state diagram, important objects and their possible states are identified, along with initial/final states and triggering events between states. Examples shown include the states of a book in a library system and an ATM machine.

Uploaded by

meet 0102
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

State diagram

A state diagram is a graph whose nodes are states and whose directed arcs are transitions
between states.

A state diagram specifies the state sequences caused by event sequences.


 The state diagram is a standard computer science concept that relates events and state.
 Events represent external stimuli.
 States represent value of objects.
 All objects in a class execute the state diagram for that class, which models their common
behavior.
 The UML notation for a state diagram is a rectangle with object name in a small pentagonal tag
in the upper left corner.

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 issued to user


Available Issue

Request to issue same book


Submit the 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 off / shut-down turn off / shut-down


off

turn on /
startup
successfully failure
Self Test

turn on /
restart
failure
service Out of
Idle Maintenance Service
service
cancel

card inserted remove card failure

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

items are available


Pending Fulfilled

10

You might also like