Download Inf111/CSE121: Use Cases, Sequence Diagrams, Activity Diagrams, and State Machines - Prof. and more Exams Computer Science in PDF only on Docsity!
Monday, February 23
Inf111/CSE121 © Susan Elliott Sim, 2009 Week 8, Slide 2
Overview
• Last Class
– Use Cases
• This Class
– Use Cases
– Sequence Diagrams
• Next Class
– Activity
– State Chart
Inf111/CSE121 © Susan Elliott Sim, 2009 Week 8, Slide 3
Use Cases
• In general, a use case should cover the full sequence
of steps from the beginning of a task until the end.
• A use case should describe the user’s interaction with
the system ...
– not the computations the system performs
– not a state machine
• A use case should independent of any particular user
interface design.
Inf111/CSE121 © Susan Elliott Sim, 2009 Week 8, Slide 4
Advantages of Use Cases
• Use cases are fast and easy to write (after some
practice). They require no training to read.
• Use cases are fairly concrete examples of how the
system could be used.
• Use cases are examples of usage. Starting with just
a few examples is easy. More examples can be
added incrementally as needed.
Inf111/CSE121 © Susan Elliott Sim, 2009 Week 8, Slide 7
How to write use cases
• As you go, add notes to yourself and questions to
come back to.
• Are there any preconditions that you assumed?
• Are there alternative ways to accomplish the same
thing? E.g., cash withdrawal vs. fast cash. You can
note them as extensions, or write whole new use
cases.
• Are there ways that the user can fail? Note some as
extensions.
Inf111/CSE121 © Susan Elliott Sim, 2009 Week 8, Slide 8
Elements of Use Case Diagrams
• The main purposes of a use case diagram:
– Show all the names of the use cases, like a table of contents
– Show relationships between actors and use cases
– Show relationships between use cases
• Stick figure: Actor
• Oval: Use case
• Extension
– Optional interactions to cover exceptions
• Inclusion
– For common substeps; can be re-used in diagram
• Generalization
– Like superclasses; for representing several similar use
cases
Inf111/CSE121 © Susan Elliott Sim, 2009 Week 8, Slide 9
Inf111/CSE121 © Susan Elliott Sim, 2009 Week 8, Slide 10
Use Case Diagram
Telephone Shopping
Customer
check status
Salesperson
place order
Shipping Clerk fill order
Supervisor
establish credit
Extensions Alternate scenarios of success or failure.
- Pay
a) Swipe Credit Card
i) MasterCard
ii) Visa
iii) Diner’s Card
iv) USA Credit Card
Validate using Zipcode
Three tries before transaction is rejected
b) Swipe Debit Card
i) MasterCard
ii) Visa
Validate using PIN
Three tries before transaction is rejected
c) Cash
d) Cannot read card
- Dispense Gas
a) Run out of gas
b) Emergency stop is activated
c) Transaction limit is reached
- Receipt
a) Accepted
b) Declined
c) No response
- Printed receipt is not taken
Special
Requirements
Related non-functional requirements
Security- no fraud
Technology and
Data Variations
List
Varying I/O methods and data formats.
Works on a gas pump with card reader, display, key pad, grade
selection buttons, printer for receipts, nozzle, speaker
May have camera
Frequency Influences investigation, testing, and timing of implementation
Once every five minutes, during hours of operation
Miscellaneous Such as open issues.
What to do when three attempts at validation fail?
Pay
Put Gas In Car
receipt fails to print
receipt
<>
pay with credit card
pay with check card
Driver
Fill Up Gas
Attendant
pay with cash
Wednesday, February 25
Inf111/CSE121 © Susan Elliott Sim, 2009 Week 8, Slide 15
Overview
• Last Class
– Use Cases
• This Class
– Sequence Diagrams
– Activity Diagrams
– State Charts
• Next Class
– Testing
Inf111/CSE121 © Susan Elliott Sim, 2009 Week 8, Slide 16
Sequence Diagrams
• System Sequence Diagrams
– For showing the interaction actors and the software system
– Next step in gathering requirements after writing use cases
• Object Sequence Diagrams
– For showing the interaction between objects
– Next step in designing classes and objects, after high-level
design (architecture, packages, initial classes)
Inf111/CSE121 © Susan Elliott Sim, 2009 Week 8, Slide 19
Pumping Gasoline
: Driver
: GasPump
Pay For Gas
Pump Gas
Gasoline
End Transaction
Request Receipt
Receipt
This is a System Sequence
Diagram. It shows steps in
the interaction between the
user and the gas pump.
Inf111/CSE121 © Susan Elliott Sim, 2009 Week 8, Slide 20
Frame and Guard
Inf111/CSE121 © Susan Elliott Sim, 2009 Week 8, Slide 21
Frame Operator
• Keyword specifies the type of frame
• Guard specifies condition
• Keywords
– loop - Loop fragment while guard is true
– opt - Optional fragment that executes if guard is true
– alt - Alternative fragment for mutual exclusion conditional
logic expressed in the guards
– par - Fragments that execute in parallel
– region - Critical region within which only one thread can
run
Inf111/CSE121 © Susan Elliott Sim, 2009 Week 8, Slide 22
Object Sequence Diagram
• More detail
• More syntax
• Can be transformed into source code
c: Customer
r:
RentalContract
p:
PricingSystem
v 1 : Video
new( c heckout Date )
addVideo( v 1 )
getP rice( v 1 )
getCategory()
calculatePrice()
addPriceToTotal()
Inf111/CSE121 © Susan Elliott Sim, 2009 Week 8, Slide 26
Making Toast
:Toaster :Slot
1 : insert(bread)
2 : insert(bread)
3 : start()
4 : pop()
Delay
depends
on darkness
setting
5 : toastReady()
Inf111/CSE121 © Susan Elliott Sim, 2009 Week 8, Slide 27
Activity Diagrams
• Used to show sequential and parallel activities in a
process
– Useful for modeling business processes, workflows, data
flows, and complex logic
– Not used to show computation of equations
Inf111/CSE121 © Susan Elliott Sim, 2009 Week 8, Slide 31
Elements of Activity Diagrams
• Start Node
– Solid disc
– Initiates process
• End Node
– Solid disc with concentric circle (simple bull’s eye)
– Wraps up process
• Object Node
– Horizontal rectangle
– Use to show objects that are produced by or used in an
activity
Inf111/CSE121 © Susan Elliott Sim, 2009 Week 8, Slide 32
Elements of Activity Diagrams
• Rake
– Similar to a downward facing capital “E”
– Shows hierarchy, i.e. there is an activity diagram inside this
action
• Decision
– Diamond
– Any one branch can exit
– Guards conditions on branches
• Merge
– Diamond
– Any incoming branch can trigger outgoing transition (unlike
join)
Inf111/CSE121 © Susan Elliott Sim, 2009 Week 8, Slide 33
How to Create Activity Diagrams
• Identify the start
– Symbolic or dummy node
• Identify the end
– Symbolic or dummy node
• Identify parties
– Who is involved?
• Identify actions
– What needs to be done?
• Identify transitions
– What happens after something is done?
– What activities depend on each other?
Inf111/CSE121 © Susan Elliott Sim, 2009 Week 8, Slide 34
State Machine Diagram
• Some objects have states and some don’t
– State-independent objects respond the same way an event
– State-dependent objects respond differently depending on
their internal state
- Need State Machine Diagrams to fully describe these kinds of
objects
• Used to show the events and states in the life of an
object
• Also called State Diagrams