Dynamic Models. Outline Dynamic Models Statecharts –States –Transitions –Composite states...
-
Upload
clifton-knight -
Category
Documents
-
view
214 -
download
0
Transcript of Dynamic Models. Outline Dynamic Models Statecharts –States –Transitions –Composite states...
![Page 1: Dynamic Models. Outline Dynamic Models Statecharts –States –Transitions –Composite states Interaction Diagrams –Sequence Diagrams The time order of interactions.](https://reader035.fdocuments.us/reader035/viewer/2022062804/5697bf771a28abf838c81709/html5/thumbnails/1.jpg)
Dynamic Models
![Page 2: Dynamic Models. Outline Dynamic Models Statecharts –States –Transitions –Composite states Interaction Diagrams –Sequence Diagrams The time order of interactions.](https://reader035.fdocuments.us/reader035/viewer/2022062804/5697bf771a28abf838c81709/html5/thumbnails/2.jpg)
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
![Page 3: Dynamic Models. Outline Dynamic Models Statecharts –States –Transitions –Composite states Interaction Diagrams –Sequence Diagrams The time order of interactions.](https://reader035.fdocuments.us/reader035/viewer/2022062804/5697bf771a28abf838c81709/html5/thumbnails/3.jpg)
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
![Page 4: Dynamic Models. Outline Dynamic Models Statecharts –States –Transitions –Composite states Interaction Diagrams –Sequence Diagrams The time order of interactions.](https://reader035.fdocuments.us/reader035/viewer/2022062804/5697bf771a28abf838c81709/html5/thumbnails/4.jpg)
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)
![Page 5: Dynamic Models. Outline Dynamic Models Statecharts –States –Transitions –Composite states Interaction Diagrams –Sequence Diagrams The time order of interactions.](https://reader035.fdocuments.us/reader035/viewer/2022062804/5697bf771a28abf838c81709/html5/thumbnails/5.jpg)
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)
![Page 6: Dynamic Models. Outline Dynamic Models Statecharts –States –Transitions –Composite states Interaction Diagrams –Sequence Diagrams The time order of interactions.](https://reader035.fdocuments.us/reader035/viewer/2022062804/5697bf771a28abf838c81709/html5/thumbnails/6.jpg)
Elements of Statechart
Idle
Initial State
Running
Final State
State
Transition
![Page 7: Dynamic Models. Outline Dynamic Models Statecharts –States –Transitions –Composite states Interaction Diagrams –Sequence Diagrams The time order of interactions.](https://reader035.fdocuments.us/reader035/viewer/2022062804/5697bf771a28abf838c81709/html5/thumbnails/7.jpg)
Initial and final
White’s turn
Black’s turn
Blackmoves
Whitemoves
start
BlackWin
Draw
WhiteWin
checkmate
checkmate
stalemate
stalemate
![Page 8: Dynamic Models. Outline Dynamic Models Statecharts –States –Transitions –Composite states Interaction Diagrams –Sequence Diagrams The time order of interactions.](https://reader035.fdocuments.us/reader035/viewer/2022062804/5697bf771a28abf838c81709/html5/thumbnails/8.jpg)
State
• All objects have state• State is an abstraction of the values maintained by
the object that determine behavior• Examples:
![Page 9: Dynamic Models. Outline Dynamic Models Statecharts –States –Transitions –Composite states Interaction Diagrams –Sequence Diagrams The time order of interactions.](https://reader035.fdocuments.us/reader035/viewer/2022062804/5697bf771a28abf838c81709/html5/thumbnails/9.jpg)
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
![Page 10: Dynamic Models. Outline Dynamic Models Statecharts –States –Transitions –Composite states Interaction Diagrams –Sequence Diagrams The time order of interactions.](https://reader035.fdocuments.us/reader035/viewer/2022062804/5697bf771a28abf838c81709/html5/thumbnails/10.jpg)
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
![Page 11: Dynamic Models. Outline Dynamic Models Statecharts –States –Transitions –Composite states Interaction Diagrams –Sequence Diagrams The time order of interactions.](https://reader035.fdocuments.us/reader035/viewer/2022062804/5697bf771a28abf838c81709/html5/thumbnails/11.jpg)
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
![Page 12: Dynamic Models. Outline Dynamic Models Statecharts –States –Transitions –Composite states Interaction Diagrams –Sequence Diagrams The time order of interactions.](https://reader035.fdocuments.us/reader035/viewer/2022062804/5697bf771a28abf838c81709/html5/thumbnails/12.jpg)
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
![Page 13: Dynamic Models. Outline Dynamic Models Statecharts –States –Transitions –Composite states Interaction Diagrams –Sequence Diagrams The time order of interactions.](https://reader035.fdocuments.us/reader035/viewer/2022062804/5697bf771a28abf838c81709/html5/thumbnails/13.jpg)
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"
![Page 14: Dynamic Models. Outline Dynamic Models Statecharts –States –Transitions –Composite states Interaction Diagrams –Sequence Diagrams The time order of interactions.](https://reader035.fdocuments.us/reader035/viewer/2022062804/5697bf771a28abf838c81709/html5/thumbnails/14.jpg)
Transitions have• Source State
• Event Trigger
• Guard Condition
• Action
• Target State
![Page 15: Dynamic Models. Outline Dynamic Models Statecharts –States –Transitions –Composite states Interaction Diagrams –Sequence Diagrams The time order of interactions.](https://reader035.fdocuments.us/reader035/viewer/2022062804/5697bf771a28abf838c81709/html5/thumbnails/15.jpg)
Transitions
Keypress [key=Enter key] / str <= input_buffer
Every transition in a statechart should be labeled.
SourceEvent [Condition] / Action
Target
![Page 16: Dynamic Models. Outline Dynamic Models Statecharts –States –Transitions –Composite states Interaction Diagrams –Sequence Diagrams The time order of interactions.](https://reader035.fdocuments.us/reader035/viewer/2022062804/5697bf771a28abf838c81709/html5/thumbnails/16.jpg)
Transitions
• Lead from one state to another
• Instantaneous
![Page 17: Dynamic Models. Outline Dynamic Models Statecharts –States –Transitions –Composite states Interaction Diagrams –Sequence Diagrams The time order of interactions.](https://reader035.fdocuments.us/reader035/viewer/2022062804/5697bf771a28abf838c81709/html5/thumbnails/17.jpg)
Conditions and Guarded Transitions
Event [condition]
Event [condition]
![Page 18: Dynamic Models. Outline Dynamic Models Statecharts –States –Transitions –Composite states Interaction Diagrams –Sequence Diagrams The time order of interactions.](https://reader035.fdocuments.us/reader035/viewer/2022062804/5697bf771a28abf838c81709/html5/thumbnails/18.jpg)
Phone Example
dial digit(n)[incomplete]
Dialing Connecting
busy
connected
dial digit(n)[valid] / connectdial digit(n)
[invalid]
Invalid
Ringing
Busy
![Page 19: Dynamic Models. Outline Dynamic Models Statecharts –States –Transitions –Composite states Interaction Diagrams –Sequence Diagrams The time order of interactions.](https://reader035.fdocuments.us/reader035/viewer/2022062804/5697bf771a28abf838c81709/html5/thumbnails/19.jpg)
Another Example
anomalyNormal Recovery
Identification
PressureRecovery
TemperatureRecovery
recovery success
recovery success
recovery success
anomaly=temperature
anomaly=pressure
recovery failure
recoveryfailure
recoveryfailure
![Page 20: Dynamic Models. Outline Dynamic Models Statecharts –States –Transitions –Composite states Interaction Diagrams –Sequence Diagrams The time order of interactions.](https://reader035.fdocuments.us/reader035/viewer/2022062804/5697bf771a28abf838c81709/html5/thumbnails/20.jpg)
Composite States
anomaly
Normal RecoveryIdentification
PressureRecovery
TemperatureRecovery
recoverysuccess
done done
temperaturepressure
Recovery
recoveryfailure
![Page 21: Dynamic Models. Outline Dynamic Models Statecharts –States –Transitions –Composite states Interaction Diagrams –Sequence Diagrams The time order of interactions.](https://reader035.fdocuments.us/reader035/viewer/2022062804/5697bf771a28abf838c81709/html5/thumbnails/21.jpg)
Composite States (Cont.)
• Used to simplify diagrams
• Inside, looks like statechart
• May have composite transitions
• May have transitions from substates
• Sequential and parallel
![Page 22: Dynamic Models. Outline Dynamic Models Statecharts –States –Transitions –Composite states Interaction Diagrams –Sequence Diagrams The time order of interactions.](https://reader035.fdocuments.us/reader035/viewer/2022062804/5697bf771a28abf838c81709/html5/thumbnails/22.jpg)
Composites and Transitions
Idle
Maintenance
Printing
Selecting Processing
Validating
Transition from substate
Transition to/from composite state
Active
![Page 23: Dynamic Models. Outline Dynamic Models Statecharts –States –Transitions –Composite states Interaction Diagrams –Sequence Diagrams The time order of interactions.](https://reader035.fdocuments.us/reader035/viewer/2022062804/5697bf771a28abf838c81709/html5/thumbnails/23.jpg)
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
![Page 24: Dynamic Models. Outline Dynamic Models Statecharts –States –Transitions –Composite states Interaction Diagrams –Sequence Diagrams The time order of interactions.](https://reader035.fdocuments.us/reader035/viewer/2022062804/5697bf771a28abf838c81709/html5/thumbnails/24.jpg)
Parallel Composition
• Concurrency (split of control)
• Synchronization
substate1 substate2
Superstate
substate3 substate4
![Page 25: Dynamic Models. Outline Dynamic Models Statecharts –States –Transitions –Composite states Interaction Diagrams –Sequence Diagrams The time order of interactions.](https://reader035.fdocuments.us/reader035/viewer/2022062804/5697bf771a28abf838c81709/html5/thumbnails/25.jpg)
Example
HW1 HW2
Incomplete
Project
Midterm Final
Passed
Failedfail
![Page 26: Dynamic Models. Outline Dynamic Models Statecharts –States –Transitions –Composite states Interaction Diagrams –Sequence Diagrams The time order of interactions.](https://reader035.fdocuments.us/reader035/viewer/2022062804/5697bf771a28abf838c81709/html5/thumbnails/26.jpg)
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
![Page 27: Dynamic Models. Outline Dynamic Models Statecharts –States –Transitions –Composite states Interaction Diagrams –Sequence Diagrams The time order of interactions.](https://reader035.fdocuments.us/reader035/viewer/2022062804/5697bf771a28abf838c81709/html5/thumbnails/27.jpg)
Example Parallel
Idle
Command
Testing
Waiting
Diagnose
Join
Fork
Composite state
Maintaining
Testing
Commanding
Concurrent States
![Page 28: Dynamic Models. Outline Dynamic Models Statecharts –States –Transitions –Composite states Interaction Diagrams –Sequence Diagrams The time order of interactions.](https://reader035.fdocuments.us/reader035/viewer/2022062804/5697bf771a28abf838c81709/html5/thumbnails/28.jpg)
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.
![Page 29: Dynamic Models. Outline Dynamic Models Statecharts –States –Transitions –Composite states Interaction Diagrams –Sequence Diagrams The time order of interactions.](https://reader035.fdocuments.us/reader035/viewer/2022062804/5697bf771a28abf838c81709/html5/thumbnails/29.jpg)
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)
![Page 30: Dynamic Models. Outline Dynamic Models Statecharts –States –Transitions –Composite states Interaction Diagrams –Sequence Diagrams The time order of interactions.](https://reader035.fdocuments.us/reader035/viewer/2022062804/5697bf771a28abf838c81709/html5/thumbnails/30.jpg)
Substates
• Used to simplify diagrams
• Sequential and parallel
• Inside, looks like statechart
• May have composite transitions
• May have transitions from substates
![Page 31: Dynamic Models. Outline Dynamic Models Statecharts –States –Transitions –Composite states Interaction Diagrams –Sequence Diagrams The time order of interactions.](https://reader035.fdocuments.us/reader035/viewer/2022062804/5697bf771a28abf838c81709/html5/thumbnails/31.jpg)
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.
![Page 32: Dynamic Models. Outline Dynamic Models Statecharts –States –Transitions –Composite states Interaction Diagrams –Sequence Diagrams The time order of interactions.](https://reader035.fdocuments.us/reader035/viewer/2022062804/5697bf771a28abf838c81709/html5/thumbnails/32.jpg)
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
![Page 33: Dynamic Models. Outline Dynamic Models Statecharts –States –Transitions –Composite states Interaction Diagrams –Sequence Diagrams The time order of interactions.](https://reader035.fdocuments.us/reader035/viewer/2022062804/5697bf771a28abf838c81709/html5/thumbnails/33.jpg)
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)
![Page 34: Dynamic Models. Outline Dynamic Models Statecharts –States –Transitions –Composite states Interaction Diagrams –Sequence Diagrams The time order of interactions.](https://reader035.fdocuments.us/reader035/viewer/2022062804/5697bf771a28abf838c81709/html5/thumbnails/34.jpg)
Sequence DiagramsOutsideActor :Kiosk
Insert Card(Customer)
PickDate(date)
Active Object
Lifeline
Time
Message
![Page 35: Dynamic Models. Outline Dynamic Models Statecharts –States –Transitions –Composite states Interaction Diagrams –Sequence Diagrams The time order of interactions.](https://reader035.fdocuments.us/reader035/viewer/2022062804/5697bf771a28abf838c81709/html5/thumbnails/35.jpg)
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
![Page 36: Dynamic Models. Outline Dynamic Models Statecharts –States –Transitions –Composite states Interaction Diagrams –Sequence Diagrams The time order of interactions.](https://reader035.fdocuments.us/reader035/viewer/2022062804/5697bf771a28abf838c81709/html5/thumbnails/36.jpg)
Sequence DiagramsOutsideActor :Kiosk :Server :CreditService
Insert Card(Customer)
PickDate(date)
Offer (seatChoice)
Select (seats)Submit(order) Charge (customer,
amount)
authorizeOKPrint(order)
![Page 37: Dynamic Models. Outline Dynamic Models Statecharts –States –Transitions –Composite states Interaction Diagrams –Sequence Diagrams The time order of interactions.](https://reader035.fdocuments.us/reader035/viewer/2022062804/5697bf771a28abf838c81709/html5/thumbnails/37.jpg)
Sequence DiagramsCaller
:Order :TicketDB :Account
Create
Reserve
Offer (seatChoice)
Select (seats)Submit(order) Debit
Bonus
Return
Destruction
Recursive Call
lifeline
![Page 38: Dynamic Models. Outline Dynamic Models Statecharts –States –Transitions –Composite states Interaction Diagrams –Sequence Diagrams The time order of interactions.](https://reader035.fdocuments.us/reader035/viewer/2022062804/5697bf771a28abf838c81709/html5/thumbnails/38.jpg)
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
![Page 39: Dynamic Models. Outline Dynamic Models Statecharts –States –Transitions –Composite states Interaction Diagrams –Sequence Diagrams The time order of interactions.](https://reader035.fdocuments.us/reader035/viewer/2022062804/5697bf771a28abf838c81709/html5/thumbnails/39.jpg)
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
![Page 40: Dynamic Models. Outline Dynamic Models Statecharts –States –Transitions –Composite states Interaction Diagrams –Sequence Diagrams The time order of interactions.](https://reader035.fdocuments.us/reader035/viewer/2022062804/5697bf771a28abf838c81709/html5/thumbnails/40.jpg)
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