Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
IT60105
Lecture 10
Statechart Diagrams
• We can draw state diagrams for each object involved in the system
• An object may be in several states of its life time. When a message arrives to
an object (event) it undergoes certain operations (action) or changes its state
• A state diagram shows how an object will react to the arrival of an event
s im p le s t a t e
S t a t e 1 S t a t e 2
E v e n t 1 / A c t i o n A
in it ia l s t a t e
E v e n t 2 [ g u a r d ] / A c t i o n B
E v e n t 3
S t a t e 3
c o m p o s it e s t a t e
f in a l s t a t e
N a m e S t a t e 1
E n t r y / A c t i o n A E x i t / A c t i o n C
S t a t e V a r i a b l e s
in t e r n a l a c EE t nv i etv r ny i t t i e// AA s cc t i o n
t i o n B
A
E x i t / A c t i o n C
• If there is no guard or if the guard is true, then for the event the actions will
be followed and it can enter [exit] to [from] a state or remain in the same
state
• Differences
– An activity diagram shows flow control from activity to activity, a statechart
diagram shows flow of control from state to state
– An activity is a set of operation to manipulate objects. On the other hand, a
state is an instance of an object. An object change its state when some event
trigger on it
– An activity diagram is used to model the behavioral view of a use case,
whereas a statechart diagram is used to model the dynamic view of objects,
which are underlying within a use case
R e c e i v e d o r d e r
[ f a i l e d ] [ o u t o f s t o c k ]
C h e c k v a l i d i t y C h e c k i n v e n t o r y W a i t s u p p l y
[ v a l i d ] [ i n s t o c k ]
C o n f i r m o r d e r
O r d e r in
q u e u e
O r d e r c h e c k f a i l e d O r d e r c h e c k v a l i d
R e je c t e d A c c e p t e d
o r d e r o r d e r
O u t o f s t o c k
W a it in g o r d e r I n s t o c k
S u p p l y a r r i v e s
O r d e r
c o n f ir m e d
C o u r s e o p e n
S c h e d u l e
f o r
r e g i s t r a t io n
D i s p a l y
C o u r s e L a s t d a t e
a s s i g n e d E n r o l l W i t h d r a w
F u l l C l o s e c o u r s e
C o u r s e f u l l
r e g i s t r a t i o n
S t u d e n t d r o p p e d
V a c c a n c y e x i s t
S e s s i o n s t a r t e d
C o u r s e b e i n g
t a u g h t
E v a l u a t i o n / S e s s i o n e n d
D is p la y F e e d b a c k
m a r k s
S t a t e M a c h i n e
D e f in e s t a t e s : S 1 , S 2 , . . . , S n
D e f in e a s t a t e : c u r r S t a t e
A l l o p e r a t io n s t o d e f i n e O n E n t r y a c t io n s
D e f in e t h e O n E n t r y o p e r a t io n / /
D e f in e a ll E v e n t s / /
Class Tube p;
Class Light l;
Class Timer t;
Class Beeper b;
Class Door d;
Contd. on
01 September, 2006 Information System Design IT60105, Autumn 2006
Internal Actions
• class Microwave {
State : IdleWithDoorOpen, IdleWithDoorClose, Initial,
CookingInterupted, Extend, CookingCompleted;
State MyState;
• void TurnOnLight();
• void TurnOffLight ();
• void TurnOffTube();
• void TurnOnTube();
• voidClearTimer();
• void SetTimer();
• void SoundWarningBeep();
• void Add1MinuteToTimer();
• void OnEntry();
void DoorOpen();
void DoorClosed();
void ButtonPushed();
void TimerTimeout();
}