Download presentation
Presentation is loading. Please wait.
Published byClifton Knight Modified over 9 years ago
1
Dynamic Models
2
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
3
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
4
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)
5
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)
6
Elements of Statechart Idle Initial State Running Final State State Transition
7
Initial and final White’s turn Black’s turn Black moves White moves start Black Win Draw White Win checkmate stalemate
8
State All objects have state State is an abstraction of the values maintained by the object that determine behavior Examples:
9
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
10
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
11
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
12
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
13
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"
14
Transitions have Source State Event Trigger Guard Condition Action Target State
15
Transitions Keypress [key=Enter key] / str <= input_buffer Every transition in a statechart should be labeled. Source Event [Condition] / Action Target
16
Transitions Lead from one state to another Instantaneous
17
Conditions and Guarded Transitions Event [condition]
18
Phone Example dial digit(n) [incomplete] Dialing Connecting busy connected dial digit(n) [valid] / connect dial digit(n) [invalid] Invalid Ringing Busy
19
Another Example anomaly Normal Recovery Identification Pressure Recovery Temperature Recovery recovery success recovery success anomaly= temperature anomaly= pressure recovery failure recovery failure recovery failure
20
Composite States anomaly Normal Recovery Identification Pressure Recovery Temperature Recovery recovery success done temperature pressure Recovery recovery failure
21
Composite States (Cont.) Used to simplify diagrams Inside, looks like statechart May have composite transitions May have transitions from substates Sequential and parallel
22
Composites and Transitions Idle Maintenance Printing Selecting Processing Validating Transition from substate Transition to/from composite state Active
23
Including Composite States Start entry / start dial tone exit / end dial tone Partial Dialing entry / number.append(n) digit(n) [number.isValid()] Dialing Dial Number Include / Dialing
24
Parallel Composition Concurrency (split of control) Synchronization substate1substate2 Superstate substate3substate4
25
Example HW1HW2 Incomplete Project MidtermFinal Passed Failed fail
26
Example of Synchronization OffOn On/StopOn/Play Off On Off Play Stop Remote Control On Off Off/Stop Play Stop MP3 Player On OffStop Play
27
Example Parallel Idle Command Testing Waiting Diagnose Join Fork Composite state Maintaining Testing Commanding Concurrent States
28
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.
29
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)
30
Substates Used to simplify diagrams Sequential and parallel Inside, looks like statechart May have composite transitions May have transitions from substates
31
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.
32
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
33
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)
34
Sequence Diagrams Outside Actor :Kiosk Insert Card(Customer) PickDate(date) Active Object Lifeline Time Message
35
Example (Cont.) Sequence of message sending
36
Sequence Diagrams Outside Actor :Kiosk :Server :CreditService Insert Card(Customer) PickDate(date) Offer (seatChoice) Select (seats) Submit(order) Charge (customer, amount) authorize OK Print(order)
37
Sequence Diagrams Caller :Order :TicketDB :Account Create Reserve Offer (seatChoice) Select (seats) Submit(order) Debit Bonus Return Destruction Recursive Call lifeline
38
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
39
Phone Call Scenario Caller lifts receiver Dial tone begins Caller dials digit (5) Dial tone ends 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
40
Sequence Diagram caller CalleePhone Line Caller lifts receiver Dial tone begins Dial tone ends Dials (5) Ringing tone connected Tone stops Ringing stops answers Phone rings Dials (5) Dials (1) Dials (2) Dials (3) Dials (4) Hang up
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.