ObjectOriented Analysis and Design - PowerPoint PPT Presentation

1 / 65
About This Presentation
Title:

ObjectOriented Analysis and Design

Description:

change in value of some entity (change event). Event Instance = an instance of an event (type) ... Ringing. routed. Connected. called phone answers / connect ... – PowerPoint PPT presentation

Number of Views:28
Avg rating:3.0/5.0
Slides: 66
Provided by: csBg
Category:

less

Transcript and Presenter's Notes

Title: ObjectOriented Analysis and Design


1
Object-Oriented Analysis and Design
Session 3b Behavioral Modeling State machine
diagrams
2
Outline
  • Introduction to State Machine...... 3
  • State Machine Diagrams Syntax and Semantics.11
  • State Hierarchy....31
  • State History Mechanism .......41
  • State Concurrency ..46
  • Concluding Example ..57
  • State Machine Diagrams and UML ...62
  • Summary ....65

3
Introduction to State Machine
4

Characterization of reactive systems
  • Continuous interaction with the environment
  • inputs and outputs are asynchronous in time.
  • Respond to interrupts.
  • Stringent time requirements.
  • Multiple possible scenarios of operation,
    depending on the history of previous behavior.
  • Based on interacting processes that operate in
    parallel.

5
Automata
  • A machine whose output behavior is not only a
    direct consequence of the current input, but also
    of some past history of its inputs.
  • Characterized by an internal state which
    represents this past experience.

6
What are Statecharts?
  • Statecharts are visual formalism for specifying
    behavior of complex systems.
  • Developed by David Harel.

restbreak
Employee
Resting
Working
7
State Machine (Automaton) Diagram
  • Graphical rendering of automata behavior

Lamp On
Lamp Off
8
Outputs and Actions
  • As the automaton changes state it can generate
    outputs

9
Extended State Machines (1)
  • Addition of variables (extended state)

ctr Integer
10
Extended State Machines (2)
  • An extended (Mealy) state machine is defined by
  • a set of input signals (input alphabet)
  • a set of output signals (output alphabet)
  • a set of states
  • a set of transitions
  • triggering signal
  • action
  • a set of extended state variables
  • an initial state designation
  • a set of final states (if terminating automaton)

11
State Machine Diagrams Syntax and Semantics
12
State Machine Diagram
top state
State
Initial pseudostate
top
Trigger
Ready
Transition
/ctr 0
stop
Done
Final state
Action
13
Statechart Diagram Elements
  • States
  • Any component or object within the system can be
    at a specific state in a given time.
  • When holding the state, an object (or a
    component) can perform activities (which can be
    interrupted).
  • Transitions
  • Specification of rules for moving between states.
  • A transition may consist of a trigger, condition,
    and an action.

14
Initial and Final States
start
Whites turn
checkmate
Black wins
stalemate
white moves
black moves
Draw
stalemate
Blacks turn
White wins
checkmate
15
Activity and Action
  • An activity
  • can be performed within a state.
  • can be continuous.
  • can be sequential.
  • takes time.
  • An action
  • can be performed within a state or during a
    transition.
  • can not be interrupted.
  • is atomic.
  • can take time.

16
Event-Driven Behavior
  • Event a type of observable occurrence
  • interactions
  • object operation invocation (call event).
  • asynchronous signal reception (signal event).
  • occurrence of time instants (time event)
  • interval expiry.
  • calendar/clock time.
  • change in value of some entity (change event).
  • Event Instance an instance of an event (type)
  • occurs at a particular time instant and has no
    duration.

17
Transitions
  • A transition is enabled if the object is at a
    state preceding the transition.
  • An enabled transition is activated upon its
    trigger activation.
  • An initial transition indicates that the default
    is entering S2.
  • A transition can connect the same state.

18
Object Behavior - General Model
  • Simple server model

InitializeObject
Handling depends on specific request type
Wait forRequest
HandleRequest
TerminateObject
19
Object Behavior and State Machines
  • Direct mapping

20
State Entry and Exit Actions
entry/lamp.on()
exit/lamp.off()
21
Order of Actions Simple Case
  • Entry actions are performed after (entering)
    transition actions.
  • Exit actions are performed before (exiting)
    transition actions.

Resulting action sequence printf(exiting) pr
intf(to off) lamp.off()
printf(exiting) printf(needless) lamp.off()
22
Internal Transitions
  • Self-transitions that bypass entry and exit.
    actions

Internal transition triggered by an off event
off/null
23
State (Do) Activities
  • Forks a concurrent thread that executes until
  • the action completes or
  • the state is exited.

do activity
do/while (true) alarm.ring()
24
Guards
  • Conditional execution of transitions
  • side-effect free

Selling
25
Guards and Events (1)
26
Guards and Events (2)
  • Special operators
  • in(a) means in state a.
  • en(b) means the occurrence of entering state b.
  • ex(c) means the occurrence of exiting state c.
  • tm(min) means trigger if min time units have
    passed.

27
Traffic Light Example
N/S may go straight
N/S may turn left
tm(1) cars in N/S left lanes
tm(1)no cars in N/S left lanes
tm(1)
tm(1)
tm(1)no cars in E/W left lanes
E/W may turn left
E/W may go straight
tm(1)cars in E/W left lanes
28
Phone Line Example
29
Static Conditional Branching
  • Merely a graphical shortcut for convenient
    rendering of decision trees.

value gt 200 /sell
value lt 100 /reject
(value gt 100) (value lt 200) /sell
30
Dynamic Conditional Branching
  • Choice pseudostate guards are evaluated only
    when the decision point is reached.

bid /gain calculatePotentialGain(value)
gain gt 200 /sell
gain lt 100 /reject
(gain gt 100) (gain lt 200) /sell
Dynamic choicepoint
31
State Hierarchy
32
States Hierarchy (1)
  • Intended to cluster together alternative states
    of a single aspect / object.
  • Results OR states. An OR state is a super-state
    of its sub-states.
  • A state that has no sub-states is a basic state.

The states in an IndentationStatus statechart
33
States Hierarchy (2)
  • States hierarchy is used for describing different
    levels of abstraction.

High Level
Detailed Level
34
States Hierarchy (3)
  • States hierarchy is used for clustering.

Un clustered
clustered
35
States Hierarchy (4)
  • Initial States one per state.
  • To be in a state is to be in ONE of its sub
    states.

36
States Hierarchy (5)
  • Graduated attack on complexity
  • states decomposed into state machines

LampFlashing
37
States Hierarchy (6)
Default transition to the initial pseudostate
  • Higher-level transitions

LampFlashing
38
States Hierarchy (7)
  • Triggered by a completion event
  • generated automatically when an immediately
    nested state machine terminates.

completion transition (no trigger)
39
States Hierarchy (8)
  • Two or more transitions may have the same
    triggered event
  • inner transition takes precedence.
  • if no transition is triggered, event is discarded.

LampFlashing
FlashOn
off/
FlashOff
40
States Hierarchy (9)
  • Same approach as for the simple case

initS2
E/actE
Actions execution sequence exS11?? exS1 ??
actE??enS2 ?? initS2 ?? enS21
41
State History Mechanism
42
History Mechanism (1)
43
History Mechanism (2)
44
History Mechanism (3)
45
History Mechanism (4)
  • Return to a previously visited hierarchical state
  • deep and shallow history options

Diagnosing
Diagnostic1
Diagnostic2
46
State Concurrency
47
Orthogonality and Concurrency (1)
  • Multiple simultaneous perspectives on the same
    entity

48
Orthogonality and Concurrency (2)
  • Describe independent components of a behavior.
  • Behavior of parts of an aggregate object.
  • Enforce synchronization of concurrent
    activities.
  • Concurrency is an AND-decomposition of a state.
  • To be in a state S is to be in ALL of its
    components. S is an AND state.

49
Orthogonality and Concurrency (3)
  • Combine multiple simultaneous descriptions

50
Orthogonality and Concurrency (4)
Use of Orthogonal Regions
No Use of Orthogonal Regions
51
Orthogonality and Concurrency (5)
  • All mutually orthogonal regions detect the same
    events and respond to them simultaneously.

52
Orthogonality and Concurrency (6)
  • Typically through shared variables or awareness
    of other regions state changes.

sane Boolean
flying Boolean
53
Transition Sequence
  • A transition might be a trigger
  • An event can trigger additional transitions
  • Several transition can be triggered within a
    single step
  • Solution
  • The number of triggered transition should be
    limited

A
C
b/d
a/c
d/a
c/b
B
D
54
Transition Forks and Joins
  • For transitions into/out of orthogonal regions

55
Reducing Multiple Transitions (1)
56
Reducing Multiple Transitions (2)
57
Concluding Example
58
Mini Organ Example (1)
59
Mini Organ Example (2)
  • The button a is used for switch the organ on and
    off
  • The organ enables a song selection and its style.
    When the organ is turned on the display shows the
    mode STYLE or SONG and its number. The default
    is song 1/sytle 1 and the mode is STYLE.
  • To select a style one need to press the b button
    and the required style number (1-9). Each style
    has a function that return its name
    StyleName(x).
  • To select a song one need to press the c button
    and the required song number(1-9). Each song has
    a function that return its name SongName(x).
  • Pressing the start button plays the current song
    following the current style. Another press stop
    the music. It is possible to change the song or
    style during music playing.

60
Mini Organ Example (3)
Events a - pressing the a button b - pressing the
b button c - pressing the c button s - pressing
the START button i - pressing the a digit button
(2-9) 1 - pressing the 1 button songend end of
song playing Variables i,j can get values
between 2-9 k,m can get values between 1-9 w
can get a song or style name
61
Mini Organ Example (4)
c
b
x
y
62
State Machine and UML
63
Dishwasher Class Diagram
64
Dishwasher State Machine Diagram
AcmeHeater
AcmeJet
Dishwasher
AcmeTank
65
Summary
  • UML uses a variant of Harels statecharts
  • adjusted to software modeling needs
  • Used to model event-driven (reactive) behavior
  • well-suited to the server model inherent in the
    object paradigm
  • Includes a number of sophisticated features that
    realize common state-machine usage patterns
  • entry/exit actions
  • state activities
  • dynamic and static conditional branching
  • Also, provides hierarchical modeling for dealing
    with very complex systems
  • hierarchical states
  • hierarchical transitions
  • orthogonality
Write a Comment
User Comments (0)
About PowerShow.com