Professional Documents
Culture Documents
ch13 State Modeling PDF
ch13 State Modeling PDF
ch13 State Modeling PDF
STATE MODELLING
Class Diagram Pros
– discovering related data and attributes
– getting a quick picture of the important
entities in a system
– seeing whether you have too few/many
classes
– seeing whether the relationships between
objects are too
complex, too many in number, simple
enough, etc.
– spotting dependencies between one
class/object and another
Class Diagram Cons
Not so great for:
– discovering algorithmic (not data-driven)
behavior
– finding the flow of steps for objects to solve
a given problem
– understanding the app's overall control flow
(event-driven?
web-based? sequential? etc.)
STATE MODELLING
Concerned with the time and sequencing of
operations-events that mark changes, states
that define the context for events and
organization of events and states.
Aspects of a system that are concerned with
time and changes are called the State
Model.
STATE MODELLING
Most imp. Concepts :
ON ON
OFF
State Diagram
on
Lamp On
on
off
off
Lamp Off
TRANSITIONS & CONDITIONS
Transition is change from one state to another.
Ex:- called phone is answered phone line
transitions from RINGING state to CONNECTED
state.
The transition is said to fire upon the change
from the source state to the target state.
The origin and target of a transition usually are
different states, but may be the same.
TRANSITIONS & CONDITIONS
GUARD CONDITION :-It’s a Boolean expression
that must be true in order for transition to occur
Ex:- “When you go out in morning (event) ”
if temp. is below freezing (condition)
then put on your gloves (next state)”
Guard condition checked only once, at time the
event occurs & transition fires if conditon is true
TRANSITIONS & CONDITIONS
GUARD CONDITION :-It’s a Boolean expression
that must be true in order for transition to occur.
E.g. 1 : a traffic light at an intersection may
change only if a road has cars waiting.
A guarded transition fires when its event occurs,
but only if the guard condition is true.
Fig shows guarded transitions for traffic lights at
an intersection. One pair of electric eyes checks
the north-south left turn lanes; another pair
checks the east-west turn lanes. If no car is in the
north-south and/or east-west turn lanes, then the
traffic light control logic is smart enough to skip
the left turn portion of the cycle.
TRANSITIONS & CONDITIONS
STATE DIAGRAM
graph whose nodes = state & Arcs = transitions
between states
specifying the sequence of states it goes
through during its lifetime in response to
events, together with the responses to those
events
describe changes in state in a procedure
Sample State Diagram
ONE SHOT DIAGRAM
State diagrams can represent continuous loops or one-
shot life cycles.
Diagram for phone line is a continuous loop
In normal usage, we do not care how the loop is started.
Opening
depress / motor up door open / motor off
depress / motor up
Closed Open
Closing
whenever state is entered by any incoming transition the
entry activity is performed
whenever state is exited by any outgoing transition the
exit activity is performed
NOTATION :- entry activity - keyword ‘entry’ & ‘/’ char
Exit activity - keyword ‘exit ’ & ‘/ ’ char
COMPLETION TRANSITION:
An arrow without event name indicates automatic
transition that fires when activity associated with state is
completed such a unlabeled transition is called
completion transition
An extension ladder has a rope, pulley & latch for raising ,
lowering & locking the extension. When latch is locked the
extension is mechanically supported & you may safely climb
ladder. to release latch you raise the extension slightly with
rope. You may then freely raise or lower the extension. The
latch produces a clacking sound as it passes rung of ladder.
The latch may be reengaged while raising the extension by
reversing direction just as the latch is passing a rung.
Prepare a state diagram of an extension ladder
Extension Ladder
Passing a
rung of ladder
Clacking Sound
Few Examples for Practice.
Draw a State Diagram for Library
Management System with Aggregation where
the Library Management System consists of
Book, Librarian and Server.
State Diagram for ATM
Draw diagram of the ATM system as well as
the server.
Identify states and events for a Photocopier
Machine (Zerox) from the given description.
Initially the machine is off. When the operator
switches on the machine, it first warms up during
which it performs some Internal Tests. Once the
tests are over, machine is ready for making
copies. When operator loads a page to be
photocopied and press ‘start’ button, machine
starts making copies according to the number of
copies selected. While machine is making
copies, it may go out of paper. Once operator
loads sufficient pages, it can start making copies
again. During the photocopy process, if paper
jam occurs in the machine, operator may need to
clean the path by removing the jammed paper to
make machine ready.
Draw diagram of Online Shopping
System
It should have product, customer and server.
State Diagram for Online
Restaurant Management
It consists of the Online Server, the Customer
and the Manager. The Server can initialize
the session for the customer and display the
the menu. The user can input the item of food
and then the server calculates the bill
accordingly and finally terminates the
session.
The manager can perform the analysis of the
user, the order of food given as well as the
staff.
The customer can order the food.
Server
Customer
Manager