dynamic models. outline dynamic models statecharts –states –transitions –composite states...

Post on 17-Jan-2016

214 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Dynamic Models

Outline

• Dynamic Models• Statecharts

– States– Transitions– Composite states

• Interaction Diagrams– Sequence Diagrams

• The time order of interactions between objects

– Communication Diagrams• Messages passed between objects

Dynamic Models

• Used to show software control– Sequence of operations and events– Transitions between states

• Used to show dynamic relationships between objects in the system– Messages– Interfaces

Modeling Dynamic Behavior

• Statechart diagram– Depicts the flow of control using states and

transitions– Generalization of finite state machines

• Two types:– Behavioral: the states and transitions; used to

describe all objects with complex behavior– Protocol: shows the legal transitions for an abstract

classifier such as a port (not discussed)

Statechart Diagram

• Network of states and transitions

• One diagram for each object with important dynamic behavior

• Independent timing of state machines for different objects (asynchronous)

Elements of Statechart

Idle

Initial State

Running

Final State

State

Transition

Initial and final

White’s turn

Black’s turn

Blackmoves

Whitemoves

start

BlackWin

Draw

WhiteWin

checkmate

checkmate

stalemate

stalemate

State

• All objects have state• State is an abstraction of the values maintained by

the object that determine behavior• Examples:

State corresponds to interval of time between events

• Events: points in time• State: interval of time; may correspond to a

continuous activity– eg waiting; eg ringing; eg flying

• State may be associated with value of object satisfying some condition– eg automobile transmission is in reverse– eg balance of account is negative

Defining state:

• Ignore attributes that don't affect behavior

• Combine set of attributes that form a parameter of the control– eg the control is not changed by changing the

digits in the phone call

State Specification• Entry:

– Action performed on entry to state

• Exit:– Action performed on

exit from state

• Do:– Action performed

while in the state

Name

Internal Activities

Internal Transitions

Login

entry/type ‘login’exit/login (username,password)do/get username and password

Events

• Something that happens at a point in time

• Stimulus from one object to another• May result in a change of state• May result in event being sent to another

object

Events are not subroutine calls

• One way transmission of information– obj1 sends event to obj2– obj2 sends event to obj1– two different events

• Events are grouped via generalization– the phone that rings depends on which digits

are dialed, but the event is "digit dialed"

Transitions have• Source State

• Event Trigger

• Guard Condition

• Action

• Target State

Transitions

Keypress [key=Enter key] / str <= input_buffer

Every transition in a statechart should be labeled.

SourceEvent [Condition] / Action

Target

Transitions

• Lead from one state to another

• Instantaneous

Conditions and Guarded Transitions

Event [condition]

Event [condition]

Phone Example

dial digit(n)[incomplete]

Dialing Connecting

busy

connected

dial digit(n)[valid] / connectdial digit(n)

[invalid]

Invalid

Ringing

Busy

Another Example

anomalyNormal Recovery

Identification

PressureRecovery

TemperatureRecovery

recovery success

recovery success

recovery success

anomaly=temperature

anomaly=pressure

recovery failure

recoveryfailure

recoveryfailure

Composite States

anomaly

Normal RecoveryIdentification

PressureRecovery

TemperatureRecovery

recoverysuccess

done done

temperaturepressure

Recovery

recoveryfailure

Composite States (Cont.)

• Used to simplify diagrams

• Inside, looks like statechart

• May have composite transitions

• May have transitions from substates

• Sequential and parallel

Composites and Transitions

Idle

Maintenance

Printing

Selecting Processing

Validating

Transition from substate

Transition to/from composite state

Active

Including Composite States

Start

entry / start dial toneexit / end dial tone

Partial Dialing

entry / number.append(n)

digit(n)

digit(n)

[number.isValid()]

Dialing

Dial Number

Include / Dialing

Parallel Composition

• Concurrency (split of control)

• Synchronization

substate1 substate2

Superstate

substate3 substate4

Example

HW1 HW2

Incomplete

Project

Midterm Final

Passed

Failedfail

Example of Synchronization

Off On

On/Stop On/PlayOff

On

Off

Play

Stop

Remote Control

On

Off

Off/Stop

Play

Stop

MP3 Player

On Off Stop Play

Example Parallel

Idle

Command

Testing

Waiting

Diagnose

Join

Fork

Composite state

Maintaining

Testing

Commanding

Concurrent States

In Class: Digital Watch

• Draw a statechart for a digital watch• The watch has a single mode button and a single

advance button. Pressing the mode button once and then pressing the advance button increments the hours by 1. Each press of the advance button increments the hour. Pressing the mode button the second time allows advancing the minutes by one. Pressing the mode button a third time displays the current time. While displaying the current time, the advance button is ignored. Pressing the mode button allows the user to set the hour again.

In Class: Office Phone

• Draw a statechart describing the operation of an office phone. Assume that the phone has keys for the digits 0-9, #, and *. It can detect when the receiver is on-hook or off-hook

• The phone is idle when the receiver is on-hook. Model phone calls.– making calls (e.g., dialing, connecting, talking), – receiving calls (e.g., ringing, talking)

Substates

• Used to simplify diagrams

• Sequential and parallel

• Inside, looks like statechart

• May have composite transitions

• May have transitions from substates

In-class: Toy Electric Train• Power is off, train is not moving.• Power turned on, train moves forward, headlight shines• Power turned off, train stops, headlight goes out.• Power turned on, headlight comes on, train does not move.• Power turned off, headlight goes off.• Power turned on, headlight comes on, train moves backward.• Power turned off, headlight goes off, train stops.• Power turned on, headlight on, train doesn’t move.• Power turned off, headlight off.• Power turned on, train moves forward, headlight on.

Interaction Diagrams

• 4 types– Sequence Diagrams

• The time order of interactions between objects

– Communication Diagrams• Messages passed between objects

– Interaction Overview Diagram• Overview diagram that hides much of the detail

– Timing Diagram • Interactions with precise time axis

Sequence diagram

• Depicts object interaction by highlighting the time ordering of method invocations

• Describes a sequence of method calls among objects

• (This is the only interaction diagram we’ll look at)

Sequence DiagramsOutsideActor :Kiosk

Insert Card(Customer)

PickDate(date)

Active Object

Lifeline

Time

Message

Example (Cont.)

: Customer : Order : Payment : Product : Supplier

place an order

process

validate

deliver

if ( payment ok )

back order

if ( not in stock )

get address

mail to address

Sequence of message sending

Sequence DiagramsOutsideActor :Kiosk :Server :CreditService

Insert Card(Customer)

PickDate(date)

Offer (seatChoice)

Select (seats)Submit(order) Charge (customer,

amount)

authorizeOKPrint(order)

Sequence DiagramsCaller

:Order :TicketDB :Account

Create

Reserve

Offer (seatChoice)

Select (seats)Submit(order) Debit

Bonus

Return

Destruction

Recursive Call

lifeline

Scenario

• Sequence of events that occurs in one particular execution

• Same def we used for use cases

  It is common (necessary) to group events into classes

• event: airline flight departs

Phone Call Scenario

• Caller lifts receiver• Dial tone begins• Caller dials digit (5)• Dial tone ends• Caller dials digit (5)• Caller dials digit (5)• Caller dials digit (1)• Caller dials digit (2)• Caller dials digit (3)• Caller dials digit (4)• Called phone begins ringing

• Ringing tone in calling phone

• Called party answers• Called phone stops ringing• Ringing tone ends in

calling phone• Phones are connected• Called party hangs up• Phones are disconnected• Caller hangs up

Sequence Diagram

caller CalleePhone LineCaller lifts receiver

Dial tone begins

Dial tone endsDials (5)

Ringing tone

connectedconnectedTone stops Ringing stops

answers

Phone rings

Dials (5)Dials (5)Dials (1)Dials (2)Dials (3)Dials (4)

Hang upHang up

top related