0% found this document useful (0 votes)
434 views21 pages

UML State Machine Diagrams PDF

(i) A Book object starts off in the "borrowable" state. (ii) The state of a Book object changes from "borrowable" to "not borrowable" when it is borrowed by a library member.
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)
434 views21 pages

UML State Machine Diagrams PDF

(i) A Book object starts off in the "borrowable" state. (ii) The state of a Book object changes from "borrowable" to "not borrowable" when it is borrowed by a library member.
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/ 21

Unified Modeling Language

http://www.uml.org/

Handout 3-2
State Machine Diagram
Describe the dynamic behavior of objects over time.

Basic Concepts
States, Transitions, Events, Action, Start/Initial state,
Stop/Final state, Activities
States: A state is a condition or situation in the life of
an object during which it satisfies some condition,
performs some actions or waits for some events.
Start/Initial state: Object's initial state.
Stop/Final state: Object's final state(end of an
objects existence).
State Machine Diagram

(Entry point of the


diagram, typically used (object
to show the state of destruction)
the object on creation.)
State Machine Diagram
Basic Concepts
Transition: represent a path (relation) between different
states of an object.
Events: Something that happens that affects the system,
and events triggers the state transitions.
- Occurs only when guard condition is true.
-
Example (events): Turn on PC, Logout, Key press
State Machine Diagram
Basic Concepts
Action: An action is the activity of an object that is initiated
by an event (The object does not accept or process
any new events until the actions associated with
the current event are complete.)

Condition: Conditions guard the transition.

Activities: Tasks performed by objects while in that state.


Examples(Activities) : Perform arithmetic, read from
memory, write on memory
State Machine Diagram

Transitions are labeled by the event_name[guard]/action


State Machine Diagram

State consist of:


- Name
- Set of variables
- Set of activities
(entry/action,
exit/action,
do/activity)
State Machine Diagram: Door

The door can be in one of three states: "Opened",


"Closed" or "Locked".
It can respond to the events Open, Close, Lock and
Unlock.
State Machine Diagram: Telephone
dialing
(Event)
State Machine Diagram: Bank account
State Machine Diagram: Bank account
An account can be in one of two states: account with
funds", zero balance.
It can respond to the events deposit funds, withdraw
funds and open bank account.
State Machine Diagram: ATM session
Student database
University database: Students enrolling in courses which are
offered by professors. The registrar's office is in charge of
maintaining a schedule of courses in a course catalog. They have the
authority to add and delete courses and to do schedule changes.
They also set enrollment limits on courses. We also want to design
the application that enables us to do the course registration.
More about actions
Actions can be further classified as:

Transitions (event /action) - Behavior of an object


that is initiated by an event.

On entry to a state (entry /action) Behavior that


occurs while entering to the state.

On exit from a state(exit / action) - Behavior that


occurs while exiting the state.

Within a state (do / action)- Behavior that object


carry out while in the state.
Student database (contd)
The states Course object undergoes
Action

Condition

Event
A seminar during registration
Figure (next slide) presents an example state machine
diagram for the Seminar class during registration.

- The rounded rectangles represent states: instances of


Seminar can be in the Proposed, Scheduled, Open For
Enrollment, Full, and Closed to Enrollment states.

- An object starts in an initial state, represented by the


closed circle, and can end up in a final state,
represented by the bordered circle.
A seminar during registration
Exercise
Draw a state machine diagram.

A student registers at the swimming school. The student will


take one or more swimming lessons followed by an
examination. Each swimming lesson is followed by another
swimming lesson or an individual examination. In order to sit
for an examination a student has to take 10 swimming
lessons.

When a student has completed an examination, three things


might happen:
1. The student passes and leaves the school.
2. The student fails, takes additional lessons, and tries again.
3. The student fails and gives up(Three repeats).
Statechart Example: Login part of an online banking system.
Logging in consists of entering a valid social security number and personal id
number, then submitting the information for validation.
Exercise
Consider the following state machine diagram which
shows how the state of a Book object in a library software
system changes between "borrowable" and "not
borrowable".

According to this diagram, what state does a Book object


start off in,
(i) "borrowable" or "not borrowable"?
(ii) Under what conditions does the state of a Book object
change from being "borrowable" to "not borrowable"?

You might also like