Information System Design: Statechart Diagrams

  • Uploaded by: api-26462544
  • 0
  • 0
  • June 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Information System Design: Statechart Diagrams as PDF for free.

More details

  • Words: 2,199
  • Pages: 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 S

t a

t e

p

le

it ia

l

t e

1

S E

in

s t a

v e n t 1

/ A

c t i o n

t a

t e

2

A

s t a t e E

v e n t 2 [ g u a r d ]

S

c o

m

p o

s it e

t a

t e

/ A

c t i o n B E v e n t 3

3

s t a t e f in

01 September, 2006

a l

Information System Design IT60105, Autumn 2006

s t a

t e

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

• 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

n

Detail State in a State-Chart Diagram • Detail of state is shown below

S

in

t e

r n

a l

N

a

t a

t e

m

e V

a

a c EE t nv i etv r ny i t t i e// AA s cc E

x i t

/ A

r i a

t i o n t i o n c t i o n

b

l e

s

E

E

n t r y

/ A

v e n t

S

c t i o n

t a

A

/ A

t e

c t i o n

B

1 E

x i t

/ A

c t i o n

A B 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

C

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

[ f a i l e

e

c e i v e

d ]

C

d

o r d

h e c k

e r

v a l i d i t y

C

h

e c k

[ v a l i d ]

v e n

[ o u t t o r y [ i n

C

01 September, 2006

i n

o n f i r m

o r d

o

f

s t o c k ] W a i t s u

s t o c k ]

e r

Information System Design IT60105, Autumn 2006

p p l y

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

O O

R

r d

e

r

c h

e

c k

r d

e

r

a

r r i v e

s

r d

r

r d e r in q u e u e

f a

i l e

d

O

e

e je c t e d o r d e r

c h

A O

W

a

S

u

t

o

it in g

u

p

p

l y

f

o

a

s t o

e

v a

c c e p t e o r d e r

r d e r

r r i v e

l i d

d

c k

I n

s t o

c k

s

O r d e r c o n f ir m

01 September, 2006

c k

e

d

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 d P

r o

p

o

s e

C

o u r s e

S

c h

e

d

u

C

l e

o u r s e a s s i g n e d

D

i s p

a

o u r s e o p e n f o r r e g i s t r a t io n

l y

E

n

L r o

C

t u

d

e

n

t

d

r o

p

p

e

C

l l

W

i t h

F

o u r s e

d

r a

w

u

l l

C

f u l l

a

c c a

n

c y

e

v a

s t

d

a

t e

l o s e c o u r s e r e g i s t r a t i o n

x i s t S

o u r s e b e i n g t a u g h t E

a

d V

l u

a

D is p la y m a r k s

01 September, 2006

e

o f f e r

C

S

i t h i n a d l i n

e

t i o

F

n

e

/ S

e

d

e

b

s s i o

a

n

e

s s i o

e

n

n

s t a

r t e

d

d

c k

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

01 September, 2006

t a

D

e

f in

e

s t a

D

e

f in

e

a

s t a

A

l l

o

r a

t io

D

e

f in

e

t h

e

D

e

f in

e

a

p

e

ll

t e

E

M

s : t e n

O

t e

a

S :

s

1

,

c u t o

E

n

v e

n

t s

S

i n 2

r r S d

n

c h

e

t r y

e ,

. . . ,

t a

f i n o

n

t e e

p

S

e

O

n

E

n

r a

t io

n

t r y

Information System Design IT60105, Autumn 2006

a

c t io

n

s

/ / / /

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;

• • • • • • • • • 01 September, 2006

void TurnOnLight(); void TurnOffLight (); void TurnOffTube(); void TurnOnTube(); voidClearTimer(); void SetTimer(); void SoundWarningBeep(); void Add1MinuteToTimer(); void OnEntry(); 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 () { 2. switch (MyState) { 3. case IdleWithDoorOpen: 4. TurnOnLight(); 5. break; 6. case IdleWithDoorClose: 7. TurnOffLight(); 8. break; 9. case Initial: 10. SetTimer(); 11. TurnOnLight(); 12. TurnOnTube(); 13. break; •

14.

case Extended :

15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26.

Add1MinuteToTimer();

break; case CookingInterupted: TurnOffTube(); ClearTimer(); break; case CookingCompleted: TurnOffTube(); TurnOffLight(); SoundWarningBeep();

break; default :

// Should signal error here..

} •

Contd…

01 September, 2006

Information System Design IT60105, Autumn 2006

Defining DoorOpen() • • • • • • • • • • • •

void Microwave :: DoorOpen () { switch (MyState) { case IdleWithDoorOpen: break; case IdleWithDoorClose: MyState = IdlewithDoorOpen;

OnEntry(); break; case Initial: MyState = cookingInterupted;

OnEntry();

• • • • • • • • • • • •

case Extended : MyState = CookingInterupted; OnEntry(); break; case CookingInterupted: break; case CookingCompleted: MyState = IdlewithDoorOpen; OnEntry(); break; default : // Should signal error here.. }

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

Related Documents