Power Point Presentation for 06cs71 Oomd Chapter 6 Yr 2009 Kss

51
Advanced State Mod eling/Ch 6 06CS71/OOMD 6.1 06CS71:Object-Oriented Modeling and Design with UML Chapter-06: Advanced State Modeli ng By Kumara swamy S Department of Computer Science & Information science and Engg

Transcript of Power Point Presentation for 06cs71 Oomd Chapter 6 Yr 2009 Kss

Page 1: Power Point Presentation for 06cs71 Oomd Chapter 6 Yr 2009 Kss

Advanced State Modeling/Ch 6

06CS71/OOMD 6.11

06CS71:Object-Oriented Modeling and Design with

UML Chapter-06: Advanced State Modeling

ByKumara swamy S

Department of Computer Science & Information science

and Engg

Page 2: Power Point Presentation for 06cs71 Oomd Chapter 6 Yr 2009 Kss

Advanced State Modeling/Ch 6

06CS71/OOMD 6.2

Teaching Points

• Nested State Diagrams• Nested States• Signal Generalization • Concurrency • A Simple State Model• Relation of Class and State Models• Summary

Page 3: Power Point Presentation for 06cs71 Oomd Chapter 6 Yr 2009 Kss

Advanced State Modeling/Ch 6

06CS71/OOMD 6.3

Nested State Diagramproblems with flat state diagrams

• Flat state diagrams are impractical for large problems.

Page 4: Power Point Presentation for 06cs71 Oomd Chapter 6 Yr 2009 Kss

Advanced State Modeling/Ch 6

06CS71/OOMD 6.4

Expanding States

• A high-level diagram with subdiagrams expanding certain states.

A submachine of VendingMa

chine

Page 5: Power Point Presentation for 06cs71 Oomd Chapter 6 Yr 2009 Kss

Advanced State Modeling/Ch 6

06CS71/OOMD 6.5

Expanding States

• A submachine is a state diagram that may be invoked as part of another state diagram.

Page 6: Power Point Presentation for 06cs71 Oomd Chapter 6 Yr 2009 Kss

Advanced State Modeling/Ch 6

06CS71/OOMD 6.6

Teaching Points

• Nested State Diagrams• Nested States• Signal Generalization • Concurrency • A Simple State Model• Relation of Class and State Models• Summary

Page 7: Power Point Presentation for 06cs71 Oomd Chapter 6 Yr 2009 Kss

Advanced State Modeling/Ch 6

06CS71/OOMD 6.7

Nested States

• To show the composite state’s commonality and share behavior.

• The composite state name labels the outer contour that entirely encloses the nested states

• E.g., Active

Page 8: Power Point Presentation for 06cs71 Oomd Chapter 6 Yr 2009 Kss

Advanced State Modeling/Ch 6

06CS71/OOMD 6.8

Page 9: Power Point Presentation for 06cs71 Oomd Chapter 6 Yr 2009 Kss

Advanced State Modeling/Ch 6

06CS71/OOMD 6.9

Page 10: Power Point Presentation for 06cs71 Oomd Chapter 6 Yr 2009 Kss

Advanced State Modeling/Ch 6

06CS71/OOMD 6.10

Nested States• Each of the nested states receives the outgoing

transitions of its composite state.

• State First, Second, and Third are nested states of state Forward.

Page 11: Power Point Presentation for 06cs71 Oomd Chapter 6 Yr 2009 Kss

Advanced State Modeling/Ch 6

06CS71/OOMD 6.11

Page 12: Power Point Presentation for 06cs71 Oomd Chapter 6 Yr 2009 Kss

Advanced State Modeling/Ch 6

06CS71/OOMD 6.12

Page 13: Power Point Presentation for 06cs71 Oomd Chapter 6 Yr 2009 Kss

Advanced State Modeling/Ch 6

06CS71/OOMD 6.13

Definitions

• A substate is a state that is nested in another state

• A state that has substates is called a composite state

• A state that has no substates is called a simple state

• Substates may be nested to any level

Page 14: Power Point Presentation for 06cs71 Oomd Chapter 6 Yr 2009 Kss

Advanced State Modeling/Ch 6

06CS71/OOMD 6.14

Teaching Points

• Nested State Diagrams• Nested States• Signal Generalization • Concurrency • A Simple State Model• Relation of Class and State Models• Summary

Page 15: Power Point Presentation for 06cs71 Oomd Chapter 6 Yr 2009 Kss

Advanced State Modeling/Ch 6

06CS71/OOMD 6.15

Signal Generalization

• A signal hierarchy permits different levels of abstraction to be used in a model.

Page 16: Power Point Presentation for 06cs71 Oomd Chapter 6 Yr 2009 Kss

Advanced State Modeling/Ch 6

06CS71/OOMD 6.16

Teaching Points

• Nested State Diagrams• Nested States• Signal Generalization • Concurrency • A Simple State Model• Relation of Class and State Models• Summary

Page 17: Power Point Presentation for 06cs71 Oomd Chapter 6 Yr 2009 Kss

Advanced State Modeling/Ch 6

06CS71/OOMD 6.17

Concurrency

• The state model implicitly supports concurrency among objects.

Page 18: Power Point Presentation for 06cs71 Oomd Chapter 6 Yr 2009 Kss

Advanced State Modeling/Ch 6

06CS71/OOMD 6.18

Aggregation Concurrency

• The aggregate state corresponds to the combined states of all the parts.

• Aggregation is the “and-relationship.”• The aggregate state is one state from the first

diagram, and a state from the second diagram, and a state from each other diagram.

• Transition for one object can depend on another object being in a given state.

Page 19: Power Point Presentation for 06cs71 Oomd Chapter 6 Yr 2009 Kss

Advanced State Modeling/Ch 6

06CS71/OOMD 6.19

The state of the car includes one state from each part.

Page 20: Power Point Presentation for 06cs71 Oomd Chapter 6 Yr 2009 Kss

Advanced State Modeling/Ch 6

06CS71/OOMD 6.20

Concurrency within an Object

• Some objects can be partitioned into subsets of attributes or links.

• Each of the partitioned subset has its own subdiagram.

• The state of the object comprises one state from each subdiagram.

• The subdiagrams need not be independent; the same event can cause transitions in more than on subdiagram.

Page 21: Power Point Presentation for 06cs71 Oomd Chapter 6 Yr 2009 Kss

Advanced State Modeling/Ch 6

06CS71/OOMD 6.21

A Gas Station Example

• Let's take a simple example, so we can draw the diagram

• When you go to a full service gas station, the attendants will begin to:– Wash your windshield– Fill your gas tank– Check your oil, and other fluids– Check your tires

Page 22: Power Point Presentation for 06cs71 Oomd Chapter 6 Yr 2009 Kss

Advanced State Modeling/Ch 6

06CS71/OOMD 6.22

A Gas Station Example

• If there are multiple attendants, you would assume that they would perform these acts in parallel

• Thus, when you arrive at the station, the path of execution will be split– Let's simplify the example (for visual reasons) and say

that only two things happen:• Fill your tank• Wash your windshield

Page 23: Power Point Presentation for 06cs71 Oomd Chapter 6 Yr 2009 Kss

Advanced State Modeling/Ch 6

06CS71/OOMD 6.23

A Gas Station Example

In Service

arrive depart

beginWash WashingWindshield

endWash

pumpGas FillingGas Tank

tankFull

Page 24: Power Point Presentation for 06cs71 Oomd Chapter 6 Yr 2009 Kss

Advanced State Modeling/Ch 6

06CS71/OOMD 6.24

Concurrent State Diagrams

• The example used a embedded state diagram to handle concurrency– The state 'In Service' contained two concurrent

threads of execution– The thread of execution splits when we enter

'In Service' state, and joins when we exit 'In Service' state

• Without embedded state diagrams, we can still represent concurrency

Page 25: Power Point Presentation for 06cs71 Oomd Chapter 6 Yr 2009 Kss

Advanced State Modeling/Ch 6

06CS71/OOMD 6.25

A Gas Station Example

arrive depart

beginWash WashingWindshield

endWash

pumpGas FillingGas Tank

tankFull

Page 26: Power Point Presentation for 06cs71 Oomd Chapter 6 Yr 2009 Kss

Advanced State Modeling/Ch 6

06CS71/OOMD 6.26

A Gas Station Example

arrive depart

beginWash WashingWindshield

endWash

pumpGas FillingGas Tank

tankFull

Divergence Convergence

Page 27: Power Point Presentation for 06cs71 Oomd Chapter 6 Yr 2009 Kss

Advanced State Modeling/Ch 6

06CS71/OOMD 6.27

Concurrency within an Object

Page 28: Power Point Presentation for 06cs71 Oomd Chapter 6 Yr 2009 Kss

Advanced State Modeling/Ch 6

06CS71/OOMD 6.28

Concurrency within an Object

• The play of a bridge rubber

Page 29: Power Point Presentation for 06cs71 Oomd Chapter 6 Yr 2009 Kss

Advanced State Modeling/Ch 6

06CS71/OOMD 6.29

Concurrent Composite State Example

NormalOperation

EW Greenafter 40 sec

EW Amberafter 5 sec

EW Red

NS Redafter 45 sec

NS Greenafter 30 sec

NS Amber

after 35 sec

after 5 sec

Page 30: Power Point Presentation for 06cs71 Oomd Chapter 6 Yr 2009 Kss

Advanced State Modeling/Ch 6

06CS71/OOMD 6.30

Synchronization of Concurrent Activities

• Sometimes one object must perform two ( or more) activities concurrently.

• The object must complete both activities before it can progress to its next state.

Splitting

control

Merging

control

Page 31: Power Point Presentation for 06cs71 Oomd Chapter 6 Yr 2009 Kss

Advanced State Modeling/Ch 6

06CS71/OOMD 6.31

Entering Selected Concurrent States: Illustration

Concurrent Composite State

S1 ...

S2 ...

S4 ...

SourceState

transitionString

S3 ...

Page 32: Power Point Presentation for 06cs71 Oomd Chapter 6 Yr 2009 Kss

Advanced State Modeling/Ch 6

06CS71/OOMD 6.32

Leaving Selected Concurrent States: Illustration

Concurrent Composite State

S1...

S2...

S4...

Target State

transitionString

S3...

...

...

Page 33: Power Point Presentation for 06cs71 Oomd Chapter 6 Yr 2009 Kss

Advanced State Modeling/Ch 6

06CS71/OOMD 6.33

State Diagram –UML notation

Page 34: Power Point Presentation for 06cs71 Oomd Chapter 6 Yr 2009 Kss

Advanced State Modeling/Ch 6

06CS71/OOMD 6.34

A Sample State Model

• A programmable thermostat controls a furnace and air conditioner to keep the current temperature equal to the target temperature.

• The user programs the thermostat using a pad of ten pushbuttons and three switches.

• Each pushbutton generates an event every time it is pushed.

• Each switch supplies a parameter value chosen from two or three possibilities.

Page 35: Power Point Presentation for 06cs71 Oomd Chapter 6 Yr 2009 Kss

Advanced State Modeling/Ch 6

06CS71/OOMD 6.35

A Sample State Model

• A Programmable Thermostat – The device controls a furnace and air

conditioner according to time-dependent attributes that the owner enters using a pad of buttons.

– User can specify eight target temperature, four on weekdays and four on weekends.

– Each target temperature has a start time and a time period.

Page 36: Power Point Presentation for 06cs71 Oomd Chapter 6 Yr 2009 Kss

Advanced State Modeling/Ch 6

06CS71/OOMD 6.36

A Sample State Model

• Buttons– TEMP UP– TEMP DOWN– TIME FWD– TIME BACK– SET CLOCK– SET DAY– RUN PRGM– VIEW PRGM– HOLD TEMP– F-C BUTTON

• Switchs– NIGHT LIGHT– SEASON– FAN

Page 37: Power Point Presentation for 06cs71 Oomd Chapter 6 Yr 2009 Kss

Advanced State Modeling/Ch 6

06CS71/OOMD 6.37

Top-level state diagram

• Contain seven concurrent subdiagrams• User Interface is shown on next page

Page 38: Power Point Presentation for 06cs71 Oomd Chapter 6 Yr 2009 Kss

Advanced State Modeling/Ch 6

06CS71/OOMD 6.38

Example:Programmable Thermostat

Thermostat

U.I. seasonswitch

fan switch

furnace relay

A/Crelay

fanrelay

Runindictor

Example of Aggregation Concurrency

Page 39: Power Point Presentation for 06cs71 Oomd Chapter 6 Yr 2009 Kss

Advanced State Modeling/Ch 6

06CS71/OOMD 6.39

Page 40: Power Point Presentation for 06cs71 Oomd Chapter 6 Yr 2009 Kss

Advanced State Modeling/Ch 6

06CS71/OOMD 6.40

Page 41: Power Point Presentation for 06cs71 Oomd Chapter 6 Yr 2009 Kss

Advanced State Modeling/Ch 6

06CS71/OOMD 6.41

Page 42: Power Point Presentation for 06cs71 Oomd Chapter 6 Yr 2009 Kss

Advanced State Modeling/Ch 6

06CS71/OOMD 6.42

Relation of Class and State Models

• A state diagram describes all or part of the behavior of the objects of a given class.

• State structure is related to and constrained by class structure.– A composite state is the aggregation of more than

one concurrent substate.– Try to make the state diagrams of subclasses indep

endent of the state diagrams of their superclasses.

Page 43: Power Point Presentation for 06cs71 Oomd Chapter 6 Yr 2009 Kss

Advanced State Modeling/Ch 6

06CS71/OOMD 6.43

6.6 Relation of Class and State Models

Inherent differences among objects are properly modeled as different classes

Temporary differences are properly modeled as different states of the same class

Composite state: aggregation of more than oneconcurrent substate

Page 44: Power Point Presentation for 06cs71 Oomd Chapter 6 Yr 2009 Kss

Advanced State Modeling/Ch 6

06CS71/OOMD 6.44

6.6 Relation of Class and State Models

3 sources of concurrency within class model

a. Aggregation of objects…each part of an aggregation has its own independent state…assembly has state that is the combination of the states of all its parts

b. Aggregation within an object…values and links areits parts…groups of them define concurrent substates of the composite object state

c. Concurrent behavior of an object figure 6.9

Page 45: Power Point Presentation for 06cs71 Oomd Chapter 6 Yr 2009 Kss

Advanced State Modeling/Ch 6

06CS71/OOMD 6.45

Quiz

• o p c e m t i o s e a t t s • n y e r r o u n c c c• e e d n s t e a t t s a a d m i g r • g n l a s i a l i i o n n e e z g a t r• n i n c o n z a t i s y o h r • h m s c b i u n e a

Page 46: Power Point Presentation for 06cs71 Oomd Chapter 6 Yr 2009 Kss

Advanced State Modeling/Ch 6

06CS71/OOMD 6.46

Solution to Exercise 6.1

Page 47: Power Point Presentation for 06cs71 Oomd Chapter 6 Yr 2009 Kss

Advanced State Modeling/Ch 6

06CS71/OOMD 6.47

Solution to Exercise 6.6

Page 48: Power Point Presentation for 06cs71 Oomd Chapter 6 Yr 2009 Kss

Advanced State Modeling/Ch 6

06CS71/OOMD 6.48

Page 49: Power Point Presentation for 06cs71 Oomd Chapter 6 Yr 2009 Kss

Advanced State Modeling/Ch 6

06CS71/OOMD 6.49

References

• Object-Oriented Modeling and Design with UML by Michael Blaha, 2nd edition, Pearson Education

• WWW

Page 50: Power Point Presentation for 06cs71 Oomd Chapter 6 Yr 2009 Kss

Advanced State Modeling/Ch 6

06CS71/OOMD 6.50

Sol 6.12

Page 51: Power Point Presentation for 06cs71 Oomd Chapter 6 Yr 2009 Kss

Advanced State Modeling/Ch 6

06CS71/OOMD 6.51