CS作业代写 Software Design and Modelling

Software Design and Modelling
UML State Machine Diagrams & Modelling
Textbook: 29
“No, no, you’re not thinking, you’re just being logical.” —

Copyright By PowCoder代写 加微信 powcoder

Learning Objectives
On completion of this topic you should be able to:
• Be aware of where state machine modelling is applicable.
• Understand UML state machine diagram notation.

(Revisited) Software Models
A static domain model (A domain class diagram)
A dynamic domain model (A system sequence diagram)
A dynamic design model (A design sequence diagram)
makePayment(cashT endered)
: Register
makePayment(cashT endered)
A static design model (A design class diagram)
If an object (or a system) can have different behavior based on its status or condition, how can we model it?
create(cashT endered)

State Machines
Definition: A state machine is a behavior model that captures the dynamic behavior of an object in terms of states, events, and state transitions.
• A state is the condition of an object at a moment in time
• An event is a significant or noteworthy occurrence that affects the object to change a
• A transition is a directed relationship between two states such that an event can cause the object to change from the prior state to the subsequent state
A visual model: UML State Machine Diagram

UML State Machine Diagram
Indicates initial state
Pickuopffrheocoekiver
transition

Example: Partial State Machine Diagram for an iPhone
Side button

How to Apply State Machine Diagrams? (1)
Determines the behavior of an object
• State-dependent object:
– Reacts differently to events depending on the object’s state
• State-independent object:
– For all events of interest, an object always reacts to the event the same way
• State-independent w.r.t. an event:
– Always responds to event the same way

How to Apply State Machine Diagrams? (2)
Guideline 1: Consider state machines for state-dependent objects with complex behavior. – Model behavior of complex reactive objects
Guideline 2: Complex state-dependent classes are less common for business information systems, and more common in communications and control applications.
Example: Complex Reactive Objects
• Physical device controllers
• Transactions and related Business
• Role Mutators (objects that change
Example: Protocols and Legal Sequences
• Communications Protocols
• UI Page/Window Flow, Navigation, or
• Use Case Operation Sequencing

Example: Web Page Navigation

Example: Process Sale Operation Sequencing
Wa it in gFor Sale
Process Sale
En te ri ngI t em s en d Sa le
Wa itingForPa yment
au th o ri zed
m ake Ca shP ay me nt
en te r It em
AuthorizingPayment
make Credi tPayment makmeSatkoerCehCecakrdPaPyamymenetnt

Transition Actions and Guards
• A transition action is an action (an object does something) when a transition happens – In a software implementation, this may represent the invocation of a method of the
class of the state machine diagram.
• A guard is a pre-condition to a transition, i.e., a transition won’t happen if the guard condition is false.
s s t t a a t te e s s
A transition action
trigger [ guard ] / action
When object is in State A:
if trigger event occurs and guard is true then
perform the behaviour action and transition object to State B.
transition

Example: Transition Action and Guard
Photography website

Exercise: Pedestrian Crossing Light
• The crossing light starts with the “Red Standing” light
• If the crossing button is pressed when the traffic light is “Red”, the crossing light
becomes “ ” and a timer starts
• When a timer reaches 30 seconds, the crossing light becomes “Flashing Red Standing”
• When a timer reaches 60 seconds, the crossing
light becomes “Red Standing”

Example: Pedestrian Crossing Light
The crossing light starts with the “Red Standing” light
Red Standing

Example: Pedestrian Crossing Light
If the crossing button is pressed when the traffic light is “Red”, the crossing light becomes “ ” and a timer starts
The button is pressed [Traffic Light is Red]/ Timer starts
Red Standing

Example: Pedestrian Crossing Light
When a timer reaches 30 seconds, the crossing light becomes “Flashing Red Standing”
Red Standing
The button is pressed [Traffic Light is Red]/ Timer starts

Flashing Red Standing
Timer reaches 30 seconds

Example: Pedestrian Crossing Light
When a timer reaches 60 seconds, the crossing light becomes “Red Standing”
Red Standing
Timer reaches 60 seconds / Reset Timer
The button is pressed [Traffic Light is Red]/ Timer starts

Flashing Red Standing
Timer reaches 30 seconds

Nested States
A state allows nesting to contain substates; a substate inherits the transitions of its superstate (the enclosing state)
Pickup receiver
[valid subscriber]
A superstate
PlayingDialTone
digit Dialing
A substate
• Transition into Active (via Pickup receiver) transitions into substate PlayingDialTone
• All substates of Active inherit the hang up transition.
Connecting
off hook / play dial tone

Choice Pseudostate
Choice pseudostate realizes a dynamic conditional branch. It evaluates the guards of the triggers of its outgoing transitions to select only one outgoing transition.
Entered PIN [PIN Correct] / Display Menu Entering PIN
Entered PIN [PIN Incorrect] / Stun Patron
Selecting Transaction
Calling Police
Selecting Transaction
Calling 28 Police
Entered PIN
Entering PIN
[PIN Correct] / Display Menu
[PIN Incorrect] / Stun Patron

Choice Pseudostate (Continue)
Choice Pseudostate can
• Have two or more outgoing transitions
[0 <= bal < min] [min <= bal] State B State C • Use predefined [else] guard – [else] outgoing transition chosen if no other guards are true [day = Monday] [else] State A State B Summary & Remarks • A state machine is dynamic model that illustrates the behavior of an object in terms of states, events, and state transitions • A state machine should be used if an object has complex behavior that depends on states or conditions • In the workshop 6 supplementary materials, you will learn how to implement state machines Lecture Identification Semester 1, 2022 © University of Melbourne 2021 These slides include materials from: Applying UML and Patterns: An Introduction to Object-Oriented Analysis and Design and Iterative Development, Third Edition, by , Inc., 2005. 程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com