Вы находитесь на странице: 1из 24

Information System Design

IT60105

Lecture 10

Statechart Diagrams

01 September, 2006 Information System Design IT60105, Autumn 2006


Lecture #10
• What is a Statechart diagram?

• Basic components in a state-chart diagram and their notations

• Difference between a state-chart diagram and an activity


diagram

• Example: Process Order in OLP system

• Example: Course Registration in SEIIT system

01 September, 2006 Information System Design IT60105, Autumn 2006


What is a Statechart Diagram?
• A state-chart diagram is used to model the dynamic aspects of the system.
The basic idea is same as the state machine in Finite Automata

• 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

– Each reaction may be a sequence of actions, possibly accompanied by a transition


from one named state to another

– An event represents the receipt of a signal, or the effect of an operation call

– An action represents the sending of a signal, or the call of an operation

01 September, 2006 Information System Design IT60105, Autumn 2006


General Structure of a State-Chart Diagram
• A state-chart diagram typically look like this

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

01 September, 2006 Information System Design IT60105, Autumn 2006


Basic Components in a State-Chart Diagram
• Two basic elements are there
– Rounded rectangle box representing the state
N a m e

– Labeled arrow indicating the transitions


E v e n t [ g u a r d c o n d i t i o n ] [ / A c t i o n

• Here, event is the message that is sent


• guard condition is the Boolean expression of attribute values that allows a
state transition only if the condition is true
• An action is the behavior that occurs when the state transition occurs

01 September, 2006 Information System Design IT60105, Autumn 2006


Detail State in a State-Chart Diagram
• Detail of state is shown below E v e n t / A c t i o n B

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

• Entry actions: that are common to every incoming transition


• Exit actions: that are common to every outgoing transition
• Self-transition: action within the state itself

• 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

01 September, 2006 Information System Design IT60105, Autumn 2006


Example: Stack Machine

01 September, 2006 Information System Design IT60105, Autumn 2006


State Diagram vs. Activity Diagram
• Similarity
– An activity diagram is a special case of a statechart diagram in which all or
most of states are activity states and all or most of the transitions are triggered
by completion of activities in the preceding state. Thus, both statechart and
activity diagrams are useful in modeling the life time of the object

• 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

01 September, 2006 Information System Design IT60105, Autumn 2006


Example: Activity Diagram
• Suppose, the use case “Process Order” in the OLP system. The
activity diagram look like:

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

01 September, 2006 Information System Design IT60105, Autumn 2006


Example: Statechart Diagram
• In the “Process Order” use case, the object that is being manipulated is,
namely, ORDER. So, a state diagram can be drawn to model how the
object changes its state in this particular use case
O r d e r a r r i v e s

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

01 September, 2006 Information System Design IT60105, Autumn 2006


Statechart Diagram: Another Example
• Suppose, a COURSE is an object in a usual “Course Registration” use case
(consider the SEIIT). Following is a state diagram to model the behavioral
view of the object COURSE
W i t h i n
d e a d l i n e
P r o p o s e
C o u r s e o f f e r

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

01 September, 2006 Information System Design IT60105, Autumn 2006


Advantages of Statechart Diagram
• A statechart diagram is used to model how the state of an
object changes in its life time

• Statechart diagrams are good describing how the behavior of


an object change across several use case executions

• However, if we are interested in modeling some behavior that


involves the several objects collaborating with each other, the
statechart diagram is not appropriate

01 September, 2006 Information System Design IT60105, Autumn 2006


Example: Microwave Oven

01 September, 2006 Information System Design IT60105, Autumn 2006


Designing Class

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 / /

01 September, 2006 Information System Design IT60105, Autumn 2006


State Attributes
• class Microwave {
State : IdleWithDoorOpen, IdleWithDoorClose, Initial,
CookingInterupted, Extend, CookingCompleted;
State MyState;

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();

01 September, 2006 Information System Design IT60105, Autumn 2006


Events Actions
• class Microwave {


void DoorOpen();
void DoorClosed();
void ButtonPushed();
void TimerTimeout();
}

01 September, 2006 Information System Design IT60105, Autumn 2006


Defining OnEntry()
1. void Microwave :: OnEntry () { 14. case Extended :
2. switch (MyState) { 15.
3. case IdleWithDoorOpen: Add1MinuteToTimer();
4. TurnOnLight(); 16. break;
5. break; 17. case CookingInterupted:
6. case IdleWithDoorClose: 18. TurnOffTube();
7. TurnOffLight(); 19. ClearTimer();
8. break; 20. break;
9. case Initial: 21. case CookingCompleted:
10. SetTimer(); 22. TurnOffTube();
11. TurnOnLight(); 23. TurnOffLight();
12. TurnOnTube(); 24. SoundWarningBeep();
13. break; 25. break;
• 26. default : // Should signal error here..
}
• Contd…

01 September, 2006 Information System Design IT60105, Autumn 2006


Defining DoorOpen()
• void Microwave :: DoorOpen () { • case Extended :
• switch (MyState) {
• MyState = CookingInterupted;
• case IdleWithDoorOpen:
• OnEntry();
• break;
• break;
• case IdleWithDoorClose:
• • case CookingInterupted:
MyState =
IdlewithDoorOpen; • break;
• • case CookingCompleted:
OnEntry(); • MyState = IdlewithDoorOpen;
• break; • OnEntry();
• case Initial: • break;
• MyState = cookingInterupted;
• default : // Should signal error here..

OnEntry(); • }

break;

01 September, 2006 Information System Design IT60105, Autumn 2006


More features in Statechart Diagram

01 September, 2006 Information System Design IT60105, Autumn 2006


Choice Pseudo-State
• A choice pseudo-state is shown as a diamond with one transition arriving
and two or more transitions leaving. The following diagram shows that
whichever state is arrived at after the choice pseudo-state is dependent on
the message format selected during execution of the previous state

01 September, 2006 Information System Design IT60105, Autumn 2006


Choice Junction-State
• Junction pseudo-states are used to chain together multiple transitions. A
single junction can have one or more incoming and one or more outgoing
transitions and a guard can be applied to each transition. Junctions are
semantic-free; a junction which splits an incoming transition into multiple
outgoing transitions realizes a static conditional branch as opposed to a
choice pseudo-state which realizes a dynamic conditional branch

01 September, 2006 Information System Design IT60105, Autumn 2006


History State
• A History State is used to remember the previous state of a state machine
when it was interrupted. The following diagram illustrates the use of
history states. The example is a state machine belonging to a washing
machine

01 September, 2006 Information System Design IT60105, Autumn 2006


Concurrent State
• A state may be divided into regions containing sub-states that exist and
execute concurrently. The example below shows that within the state
"Applying Brakes", the front and rear brakes will be operating
simultaneously and independently. Notice the use of fork and join pseudo-
states rather than choice and merge pseudo-states. These symbols are used
to synchronize the concurrent threads

01 September, 2006 Information System Design IT60105, Autumn 2006

Вам также может понравиться