34
1 29/06/2013 11:39:41 Marc Conrad http://perisic.com/marc 1 Object Oriented System Design Marc Conrad D104 (Park Square Building) Email: [email protected] WWW: http://perisic.com/marc This week: State Diagrams More: http://perisic.com/oosd

Object Oriented System Design - · PDF fileObject Oriented System Design ... A transition is a change of an object from one state (the source state) to another (the target state)

  • Upload
    vukhanh

  • View
    219

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Object Oriented System Design -  · PDF fileObject Oriented System Design ... A transition is a change of an object from one state (the source state) to another (the target state)

1

29/06/2013 11:39:41 Marc Conrad

http://perisic.com/marc 1

Object Oriented System Design

Marc Conrad

D104 (Park Square Building)

Email: [email protected]

WWW: http://perisic.com/marc

This week:

State Diagrams

More: http://perisic.com/oosd

Page 2: Object Oriented System Design -  · PDF fileObject Oriented System Design ... A transition is a change of an object from one state (the source state) to another (the target state)

2

29/06/2013 11:40:15 Marc Conrad

http://perisic.com/marc 2

Static Models and Dynamic Models

Class diagrams model the static behaviour of objects, i.e.

Attributes of objects

Operation of objects

Relationships between objects.

Statechart diagrams model the dynamic behaviour of objects.

More: http://perisic.com/oosd

Page 3: Object Oriented System Design -  · PDF fileObject Oriented System Design ... A transition is a change of an object from one state (the source state) to another (the target state)

3

29/06/2013 11:40:28 Marc Conrad

http://perisic.com/marc 3

Statechart diagrams

State diagrams illustrate the dynamical behaviour of an object.

State diagrams are about events and transitions. Events trigger a state change.

Transitions show the change from one state to another.

See google (images, statechart) for real-life examples.

More: http://perisic.com/oosd

Page 4: Object Oriented System Design -  · PDF fileObject Oriented System Design ... A transition is a change of an object from one state (the source state) to another (the target state)

4

29/06/2013 11:40:36 Marc Conrad

http://perisic.com/marc 4

States (definition)

A state is a condition in which an object can be at some point during its lifetime, for some finite amount of time.

An object can

perform an activity

wait for an event

More: http://perisic.com/oosd

Page 5: Object Oriented System Design -  · PDF fileObject Oriented System Design ... A transition is a change of an object from one state (the source state) to another (the target state)

5

29/06/2013 11:40:39 Marc Conrad

http://perisic.com/marc 5

Example of a state

The UML notation for a state is a rectangle with rounded corners.

Typing Password

entry/ set echo invisible

exit/ set echo visible

do/ handle characters

event request help/ display help

More: http://perisic.com/oosd

Page 6: Object Oriented System Design -  · PDF fileObject Oriented System Design ... A transition is a change of an object from one state (the source state) to another (the target state)

6

29/06/2013 11:40:40 Marc Conrad

http://perisic.com/marc 6

Typing Password

entry/ set echo invisible

exit/ set echo visible

do/ handle characters

event request help/ display help

Example of a state

The name of the state. Each state must have a different name.

Nameless states are also allowed and are considered as being different.

More: http://perisic.com/oosd

Page 7: Object Oriented System Design -  · PDF fileObject Oriented System Design ... A transition is a change of an object from one state (the source state) to another (the target state)

7

29/06/2013 11:40:41 Marc Conrad

http://perisic.com/marc 7

Typing Password

entry/ set echo invisible

exit/ set echo visible

do/ handle characters

event request help/ display help

Example of a state

An action which is performed when the state is entered.

entry/ is a keyword in states

More: http://perisic.com/oosd

Page 8: Object Oriented System Design -  · PDF fileObject Oriented System Design ... A transition is a change of an object from one state (the source state) to another (the target state)

8

29/06/2013 11:40:42 Marc Conrad

http://perisic.com/marc 8

Typing Password

entry/ set echo invisible

exit/ set echo visible

do/ handle characters

event request help/ display help

Example of a state

An action which is performed on exit from the state.

exit/ is a keyword in states

More: http://perisic.com/oosd

Page 9: Object Oriented System Design -  · PDF fileObject Oriented System Design ... A transition is a change of an object from one state (the source state) to another (the target state)

9

29/06/2013 11:40:43 Marc Conrad

http://perisic.com/marc 9

Typing Password

entry/ set echo invisible

exit/ set echo visible

do/ handle characters

event request help/ display help

Example of a state

An action which is performed while the machine is in this state.

do/ is a keyword.

More: http://perisic.com/oosd

Page 10: Object Oriented System Design -  · PDF fileObject Oriented System Design ... A transition is a change of an object from one state (the source state) to another (the target state)

10

29/06/2013 11:40:43 Marc Conrad

http://perisic.com/marc 10

Typing Password

entry/ set echo invisible

exit/ set echo visible

do/ handle characters

event request help/ display help

Example of a state

An event which triggers an internal transition. The object is not leaving its state while the event is dealt with.

More: http://perisic.com/oosd

Page 11: Object Oriented System Design -  · PDF fileObject Oriented System Design ... A transition is a change of an object from one state (the source state) to another (the target state)

11

29/06/2013 11:40:44 Marc Conrad

http://perisic.com/marc 11

Transitions

A transition is a change of an object from one state (the source state) to another (the target state).

A transition is triggered when an event of interest of the given object occurs.

Alternatively, a transition may be executed unconditionally when the activity associated with the source state is complete (triggerless transition) .

More: http://perisic.com/oosd

Page 12: Object Oriented System Design -  · PDF fileObject Oriented System Design ... A transition is a change of an object from one state (the source state) to another (the target state)

12

29/06/2013 11:40:45 Marc Conrad

http://perisic.com/marc 12

Transitions

Transition triggered by the press button event.

Printing

entry/ print

press button

Triggerless transition (executed when the receipt is printed)

More: http://perisic.com/oosd

Page 13: Object Oriented System Design -  · PDF fileObject Oriented System Design ... A transition is a change of an object from one state (the source state) to another (the target state)

13

29/06/2013 11:40:46 Marc Conrad

http://perisic.com/marc 13

Transitions and Actions

There may be an action associated with a triggered transition. This action executes before the object enters the target state.

File Saving Errordisk full / beep

Action

More: http://perisic.com/oosd

Page 14: Object Oriented System Design -  · PDF fileObject Oriented System Design ... A transition is a change of an object from one state (the source state) to another (the target state)

14

29/06/2013 11:40:47 Marc Conrad

http://perisic.com/marc 14

Self-transition

A self-transition is a transition whose source state and target state are the same.

Note that entry and exit actions are executed at a self-transition.

Example: redraw is executed each time at backup.

Editing

entry/ redrawafter 10 minutes / backup

More: http://perisic.com/oosd

Page 15: Object Oriented System Design -  · PDF fileObject Oriented System Design ... A transition is a change of an object from one state (the source state) to another (the target state)

15

29/06/2013 11:40:48 Marc Conrad

http://perisic.com/marc 15

Example: not a self-transition

redraw is not executed when the backup is made.

Editing

entry/ redraw

event after 10 minutes/ backup

More: http://perisic.com/oosd

Page 16: Object Oriented System Design -  · PDF fileObject Oriented System Design ... A transition is a change of an object from one state (the source state) to another (the target state)

16

29/06/2013 11:40:49 Marc Conrad

http://perisic.com/marc 16

Guard conditions A guard condition is a condition which must

be true before a given transition is triggered.

Notation of event with guard:

eventName[guard condition]

Event, guard, and action:

eventName[guard condition]/action

Guard only:

[guard condition]

More: http://perisic.com/oosd

Page 17: Object Oriented System Design -  · PDF fileObject Oriented System Design ... A transition is a change of an object from one state (the source state) to another (the target state)

17

29/06/2013 11:40:49 Marc Conrad

http://perisic.com/marc 17

Example for a guard condition

Transition is triggered only when password is correct.

Login

Screen

Session

running

click Login[ correct password ] / start windows

logout / exit windows

More: http://perisic.com/oosd

Page 18: Object Oriented System Design -  · PDF fileObject Oriented System Design ... A transition is a change of an object from one state (the source state) to another (the target state)

18

29/06/2013 11:40:50 Marc Conrad

http://perisic.com/marc 18

Example for an eventless guard condition

Guard condition with self transition.

Prompt for

Login

[ wrong password ]

More: http://perisic.com/oosd

Page 19: Object Oriented System Design -  · PDF fileObject Oriented System Design ... A transition is a change of an object from one state (the source state) to another (the target state)

19

29/06/2013 11:40:51 Marc Conrad

http://perisic.com/marc 19

Transition (Summary)

Transition -- Event [Guard]/Action

Trigger

event that

causes the

execution

of the

action.

Logical

condition

Action whose

execution makes

state change

happen

More: http://perisic.com/oosd

Page 20: Object Oriented System Design -  · PDF fileObject Oriented System Design ... A transition is a change of an object from one state (the source state) to another (the target state)

20

29/06/2013 11:40:52 Marc Conrad

http://perisic.com/marc 20

What is an event?

The following occurrences are considered as events in UML:

A signal

A call event

A time event

A change event

More: http://perisic.com/oosd

Page 21: Object Oriented System Design -  · PDF fileObject Oriented System Design ... A transition is a change of an object from one state (the source state) to another (the target state)

21

29/06/2013 11:40:53 Marc Conrad

http://perisic.com/marc 21

What is an event? SignalEvent

A signal

An asynchoronous communication between objects.

A call event

A time event

A change event

Wait for

Fax

Receive

Fax incoming call

More: http://perisic.com/oosd

Page 22: Object Oriented System Design -  · PDF fileObject Oriented System Design ... A transition is a change of an object from one state (the source state) to another (the target state)

22

29/06/2013 11:40:53 Marc Conrad

http://perisic.com/marc 22

What is an event? Call Events

A signal

A call event

A synchronous communication where an object sends a message to another object.

A time event

A change event

Book

closed

Book openstart reading

There is no notational difference between Signal Events and Call Events in Statechart diagrams.

More: http://perisic.com/oosd

Page 23: Object Oriented System Design -  · PDF fileObject Oriented System Design ... A transition is a change of an object from one state (the source state) to another (the target state)

23

29/06/2013 11:40:54 Marc Conrad

http://perisic.com/marc 23

What is an event? Time Events

A signal

A call event

A time event

An event that occurs after a specified period of time. A time event is expressed using the word “after” followed by a time expression.

A change event

Prompt for

Confirm

Rebootafter 60 seconds

More: http://perisic.com/oosd

Page 24: Object Oriented System Design -  · PDF fileObject Oriented System Design ... A transition is a change of an object from one state (the source state) to another (the target state)

24

29/06/2013 11:40:55 Marc Conrad

http://perisic.com/marc 24

What is an event? Change Events

A signal

A call event A time event

A change event

An event that occurs when some condition is satisfied. A change event is expressed using the keyword “when”.

Save

confirmed

Save to

disk

when disk ready

More: http://perisic.com/oosd

Page 25: Object Oriented System Design -  · PDF fileObject Oriented System Design ... A transition is a change of an object from one state (the source state) to another (the target state)

25

29/06/2013 11:40:56 Marc Conrad

http://perisic.com/marc 25

What is an action?

An action is a procedural expression that is executed when the transition fires.

The action must be executed entirely before any other actions are considered. It is not interruptible.

More: http://perisic.com/oosd

Page 26: Object Oriented System Design -  · PDF fileObject Oriented System Design ... A transition is a change of an object from one state (the source state) to another (the target state)

26

29/06/2013 11:40:56 Marc Conrad

http://perisic.com/marc 26

Initial state and final state

There are special symbols for a state where the flow of control starts and a symbol for a final state.

do something

useful

Initial state Final state

More: http://perisic.com/oosd

Page 27: Object Oriented System Design -  · PDF fileObject Oriented System Design ... A transition is a change of an object from one state (the source state) to another (the target state)

27

29/06/2013 11:40:57 Marc Conrad

http://perisic.com/marc 27

Substates

A state diagram can be refined further by dividing a state into several substates. This will give much richer information about the system to be developed.

Faxing

Dialing Waiting Sending Dialing Waiting Sending

More: http://perisic.com/oosd

Page 28: Object Oriented System Design -  · PDF fileObject Oriented System Design ... A transition is a change of an object from one state (the source state) to another (the target state)

28

29/06/2013 11:40:58 Marc Conrad

http://perisic.com/marc 28

Substates and transitions (1)

Faxing

Dialing Waiting Sending Dialing Waiting Sending

Idle

Transitions can be drawn directly to and from nested states.

More: http://perisic.com/oosd

Page 29: Object Oriented System Design -  · PDF fileObject Oriented System Design ... A transition is a change of an object from one state (the source state) to another (the target state)

29

29/06/2013 11:40:59 Marc Conrad

http://perisic.com/marc 29

Substates and transitions (2)

When a transition ends in the composite state the flow continues with the initial state in the composite state.

Faxing

Dialing Waiting Sending Dialing Waiting Sending

Idle

More: http://perisic.com/oosd

Page 30: Object Oriented System Design -  · PDF fileObject Oriented System Design ... A transition is a change of an object from one state (the source state) to another (the target state)

30

29/06/2013 11:41:00 Marc Conrad

http://perisic.com/marc 30

State Machines A statechart diagram shows an object’s state

machine:

The states that an object can assume during its life.

The events to which that object can respond.

The possible responses the object can make to those events.

The transitions that occur between the object’s states.

More: http://perisic.com/oosd

Page 31: Object Oriented System Design -  · PDF fileObject Oriented System Design ... A transition is a change of an object from one state (the source state) to another (the target state)

31

29/06/2013 11:41:00 Marc Conrad

http://perisic.com/marc 31

Statechart diagrams and state machines

Semantics

A state machine is a graph of states and transitions that describes the response of an object of a given class to the receipt of outside stimuli. A state machine is attached to a class or a method

Notation

A statechart diagram represents a state machine. The states are represented by state symbols and the transitions are represented by arrows connecting the state symbols. States may also contain subdiagrams by physical containment and tiling.

More: http://perisic.com/oosd

Page 32: Object Oriented System Design -  · PDF fileObject Oriented System Design ... A transition is a change of an object from one state (the source state) to another (the target state)

32

29/06/2013 11:41:01 Marc Conrad

http://perisic.com/marc 32

Empty

Loaded

Full

create stack pushl[ not full ]

pop/error push

push / error

pop

pop[ not empty ]

pop[ empty ]

push[full ]

Example: The statechart diagram of a stack

More: http://perisic.com/oosd

Page 33: Object Oriented System Design -  · PDF fileObject Oriented System Design ... A transition is a change of an object from one state (the source state) to another (the target state)

33

29/06/2013 11:41:03 Marc Conrad

http://perisic.com/marc 33

Detailed Statechart diagram for the Deposit Item Receiver object, 1st version.

idle

do/ wait for user

Process item Add Item to

Receipt basis

Classify

item

Create Receipt

basis

Add Item to

Receipt

basis

Classify item

Create Receipt

basis

Print Receipt

Sum items print Sum items print

item in slot( i )

press receipt button

/ create deposit item

[ further item ] / create deposit item

[ first item ]

More: http://perisic.com/oosd

Page 34: Object Oriented System Design -  · PDF fileObject Oriented System Design ... A transition is a change of an object from one state (the source state) to another (the target state)

34

29/06/2013 11:41:04 Marc Conrad

http://perisic.com/marc 34

Statechart diagram for the Deposit Item Receiver object, 2nd version

Idle

do/ wait for user

Print

Receipt

Process item

entry/ classify item

entry/ add item

receipt printed

item in slot( i )

button pressed[ item inserted ]

More: http://perisic.com/oosd