Title: Scenarios, Use Cases and Use Case Diagrams
1Scenarios, Use Cases and Use Case Diagrams
2Quick!
- Name three of the main artifacts found on a use
case diagram
3Session Goals
- At the end of this session, you will be able to
- Define and juxtapose scenario and use case
- Describe how to interpret and create use case
diagrams - Synchronize use case diagrams and elaborated
(written) use cases
4Scenarios and Use Cases
Actor an entity that can interact with a system,
invoking some behavior
Scenario a specific sequence of actions and
interactions between actors and the system being
discussed
Use Case a collection of related success and
failure scenarios
5Actors
- Actors stimulate the system
- Some like to model actors that the system
stimulates - Not as common
- Actors do not have to be human
- Actors represent a role, not a specific entity
6Actors - Example
- Pat is an ATM technician for bank
- Pat also has accounts with the bank
- Defining an ATMs functionality requires we think
of functionality needed by a technician and an
account holder - Pat can play the role of either depending on his
goal at any given time
7Scenario - Example
Card Rejected Account Holder places card in
slot. System prompts user for PIN. User enters
PIN. PIN is not valid for the given card. Card is
rejected.
- Scenarios represent one possible outcome of the
actor-system interaction
Successful Withdrawal Account Holder places card
in slot. System prompts Account Holder for PIN
and Account Holder enters PIN. The system
determines the PIN is valid for the card. The
Account Holder selects a Withdrawal Transaction.
The system ensures the account has enough money.
The system deducts the requested amount from the
account and dispenses cash to Account Holder.
8Activity
- Using the system overview provided
- Identify actors
- Identify scenarios
- Elaborate one scenario
9Use Case Example
- Use Cases glue together related scenarios
- Scenarios are related by a common goal
- Often represent different success and failures
related to a common stimuli - Use cases consist of at least one main scenario
- May have any number of alternatives (including
zero)
10Use Case - Example
Use Case Withdrawal 1. Account Holder places
card in slot. 2. System prompts Account Holder
for PIN 3. Account Holder enters PIN. 4. System
determines the PIN is valid for the card. 5.
Account Holder selects a Withdrawal
Transaction. 6. System prompts for amount to be
withdrawn. 7. Account Holder enters amount to be
withdrawn. 8. System determines the account has
sufficient funds. 9. System deducts the
requested amount from the account. 10. System
dispenses cash to Account Holder. Alternative
Card rejected 4. System determines PIN is not
valid for the card. 5. System rejects
card. Alternative Insufficient funds 8. System
determines the account does not have sufficient
funds for withdrawal. 9. System displays
appropriate message and returns card.
11Use Case - Example
Alternatives are deviations from a specific step
in the main scenario
Use Case Withdrawal 1. Account Holder places
card in slot. 2. System prompts Account Holder
for PIN 3. Account Holder enters PIN. 4. System
determines the PIN is valid for the card. 5.
Account Holder selects a Withdrawal
Transaction. 6. System prompts for amount to be
withdrawn. 7. Account Holder enters amount to be
withdrawn. 8. System determines the account has
sufficient funds. 9. System deducts the
requested amount from the account. 10. System
dispenses cash to Account Holder. Alternative
Card rejected 4. System determines PIN is not
valid for the card. 5. System rejects
card. Alternative Insufficient funds 8. System
determines the account does not have sufficient
funds for withdrawal. 9. System displays
appropriate message and returns card.
The first step in the alternative replaces the
step of the same number in the main scenario
12Use Case - Example
Use Case Withdrawal 1. Account Holder places
card in slot. 2. System prompts Account Holder
for PIN 3. Account Holder enters PIN. 4. System
determines the PIN is valid for the card. 5.
Account Holder selects a Withdrawal
Transaction. 6. System prompts for amount to be
withdrawn. 7. Account Holder enters amount to be
withdrawn. 8. System determines the account has
sufficient funds. 9. System deducts the
requested amount from the account. 10. System
dispenses cash to Account Holder. Alternative
Card rejected 4. System determines PIN is not
valid for the card. 5. System rejects
card. Alternative Insufficient funds 8. System
determines the account does not have sufficient
funds for withdrawal. 9. System displays
appropriate message and returns card.
1. Account Holder places card in slot. 2. System
prompts Account Holder for PIN and Account Holder
enters PIN. 3. The system determines the PIN is
valid for the card. 4. The Account Holder
selects a Withdrawal Transaction.
1. Account Holder places card in slot. 2. System
prompts Account Holder for PIN 3. Account Holder
enters PIN. 4. System determines the PIN is
valid for the card. 5. Account Holder selects a
Withdrawal Transaction. 6. System prompts for
amount to be withdrawn. 7. Account Holder enters
amount to be withdrawn. 8. System determines the
account has sufficient funds.
The scenario Insufficient Funds consists of the
highlighted steps.
9. System deducts the requested amount from the
account. 10. System dispenses cash to Account
Holder.
8. System determines the account does not have
sufficient funds for withdrawal. 9. System
displays appropriate message and returns card.
13Rejoining the Main Scenario
- Alternatives may rejoin the main scenario
- Use Case Check in for flight
- User presses Begin.
- System prompts user for last name.
- User enters last name.
- System prompts user for first name.
- User enters first name.
- System finds and displays related flight
information. - User selects flight.
- System prompts user to enter number of bags to
check. - . . .
- Alternative User uses credit card
- 3. User inserts credit card into slot.
- 4. System reads user information from credit
card. - Return to step 6 in main scenario.
14Other Variations
- There are other possible variations
- It is best to keep things simple
- Too much jumping around leads to confusion
- Alternatives should never be a deviation from an
alternative
15Use Case Diagram
System
ATM
Actor
Withdraw
Account Holder
Use Case
16Use Case Diagrams
- Things to note
- Usually only actors that stimulate the system are
depicted - Actors can be involved with multiple use cases
- Use cases can be associated to multiple actors
- Use Case Diagrams only depict use cases, not
individual scenarios
17Activity
- Using the scenarios discovered in the previous
exercise - Identify related scenarios
- Elaborate at least one use case
- Create a use case diagram for the system
18Use Cases Include Relationship
- Some Use Cases have a chunk of behavior that is
similar in each Use Case
Use Case Withdrawal 1. Account Holder places
card in slot. 2. System prompts Account Holder
for PIN and Account Holder enters PIN. 3. The
system determines the PIN is valid for the card.
4. The Account Holder selects a Withdrawal
Transaction. . . .
Use Case Deposit 1. Account Holder places card
in slot. 2. System prompts Account Holder for
PIN and Account Holder enters PIN. 3. The
system determines the PIN is valid for the card.
4. The Account Holder selects a Deposit
Transaction. . . .
Use Case Check Balance 1. Account Holder places
card in slot. 2. System prompts Account Holder
for PIN and Account Holder enters PIN. 3. The
system determines the PIN is valid for the card.
4. The Account Holder selects a Check Balance
Transaction. . . .
19Use Cases Include Relationship
- The include relationship lets us separate out the
common behavior and import it
Use Case Validate 1. Account Holder places card
in slot. 2. System prompts Account Holder for PIN
and Account Holder enters PIN. 3. The system
determines the PIN is valid for the card. . . .
Use Case Withdrawal 1. Include Validate. 2. The
Account Holder selects a Withdrawal Transaction.
. . .
Use Case Deposit 1. Include Validate. 2. The
Account Holder selects a Deposit Transaction. .
. .
Use Case Check Balance 1. Include Validate. 2.
The Account Holder selects a Check Balance
Transaction. . . .
20Use Cases Include Relationship
- Alternatives may also be in included use cases
Use Case Validate 1. Account Holder places card
in slot. 2. System prompts Account Holder for
PIN 3. Account Holder enters PIN. 4. The system
determines the PIN is valid for the card.
Alternative Card rejected 4. System determines
PIN is not valid for the card. 5. System rejects
card.
Use Case Withdrawal 1. Include Validate. 2. The
system determines the PIN is valid for the card.
3. The Account Holder selects a Withdrawal
Transaction. 4. The system ensures the account
has enough money. 5. The system deducts the
requested amount from the account. 6. System
dispenses cash to Account Holder. Alternative
Insufficient funds 4. System determines the
account does not have sufficient funds for
withdrawal. 5. System displays appropriate
message and returns card.
21Use Cases Include Relationship
- When one use case includes another, you can think
of gluing them together
Use Case Validate 1. Account Holder places card
in slot. 2. System prompts Account Holder for
PIN 3. Account Holder enters PIN. 4. The system
determines the PIN is valid for the card.
Alternative Card rejected 4. System determines
PIN is not valid for the card. 5. System rejects
card.
Use Case Withdrawal 1. Account Holder places
card in slot. 2. System prompts Account Holder
for PIN 3. Account Holder enters PIN. 4. The
system determines the PIN is valid for the card.
5. The Account Holder selects a Withdrawal
Transaction. 6. The system ensures the account
has enough money. 7. The system deducts the
requested amount from the account. 8. System
dispenses cash to Account Holder. Alternative
Card rejected 4. System determines PIN is not
valid for the card. 5. System rejects
card. Alternative Insufficient funds 6. System
determines the account does not have sufficient
funds for withdrawal. 7. System displays
appropriate message and returns card.
Use Case Withdrawal 1. Include Validate. 2. The
system determines the PIN is valid for the card.
3. The Account Holder selects a Withdrawal
Transaction. 4. The system ensures the account
has enough money. 5. The system deducts the
requested amount from the account. 6. System
dispenses cash to Account Holder. Alternative
Insufficient funds 4. System determines the
account does not have sufficient funds for
withdrawal. 5. System displays appropriate
message and returns card.
22Use Case Diagrams Include Relationship
ATM
Withdraw
ltltincludegtgt
ltltincludegtgt
Deposit
Validate
Check Balance
ltltincludegtgt
Account Holder
23Activity
- Using the use cases from the previous exercises,
identify any include relationships - Elaborate two use cases involved in an include
relationship
24Use Cases Extend Relationship
- The extend relationship can be used to split up a
use case - Useful for complicated use cases
- Requires the use of explicit extension points
- Extensions can occur at specific points and no
where else - Unlike included use cases, extended use cases
stand on their own
25Use Cases Extend Example
Use Case Deposit Main Scenario 1. Include
Validate. 2. The Account Holder selects
Deposit. 3. The system retrieves the account
information and prompts Account Holder for amount
to deposit. 4. The Account Holder enters the
amount. 5. XP The system starts the deposit slot
mechanism. 6. The Account Holder places the
deposit item into the deposit slot mechanism. 7.
The system detects the deposit item and stops the
deposit slot mechanism. 8. The system adds the
deposit amount to the account. 9. The card is
returned to the Account Holder. Alternative
Deposit Slot Mechanism Times Out 6. The Account
Holder does not place the deposit item in the
deposit slot mechanism within 5 seconds. 7. The
system did not detect a deposit item and stops
the deposit slot mechanism 8. The system displays
an error message to the Account Holder. 9. The
card is returned to the user.
Use Case Deposit Main Scenario 1. Include
Validate. 2. The Account Holder selects
Deposit. 3. The system retrieves the account
information and prompts Account Holder for amount
to deposit. 4. The Account Holder enters the
amount. 5. The system starts the deposit slot
mechanism. 6. The Account Holder places the
deposit item into the deposit slot mechanism. 7.
The system detects the deposit item and stops the
deposit slot mechanism. 8. The system adds the
deposit amount to the account. 9. The card is
returned to the Account Holder. Alternative
Deposit Slot Mechanism Fails to Start 5. The
system fails to start the deposit slot
mechanism. 6. The system displays an error
message to the Account Holder. 7. The card is
returned to the Account Holder. Alternative
Deposit Slot Mechanism Times Out 6. The Account
Holder does not place the deposit item in the
deposit slot mechanism within 5 seconds. 7. The
system did not detect a deposit item and stops
the deposit slot mechanism 8. The system displays
an error message to the Account Holder. 9. The
card is returned to the user.
Use Case Deposit Extends Deposit Main
Scenario Replace XP with 1. The system fails to
start the deposit slot mechanism. 2. The system
displays an error message to the Account
Holder. 3. The card is returned to the Account
Holder.
26Use Cases Extend Example
Use Case Deposit Main Scenario 1. Include
Validate. 2. The Account Holder selects
Deposit. 3. The system retrieves the account
information and prompts Account Holder for amount
to deposit. 4. The Account Holder enters the
amount. 5. XP The system starts the deposit slot
mechanism. 6. The Account Holder places the
deposit item into the deposit slot mechanism. 7.
The system detects the deposit item and stops the
deposit slot mechanism. 8. The system adds the
deposit amount to the account. 9. The card is
returned to the Account Holder. Alternative
Deposit Slot Mechanism Times Out 6. The Account
Holder does not place the deposit item in the
deposit slot mechanism within 5 seconds. 7. The
system did not detect a deposit item and stops
the deposit slot mechanism 8. The system displays
an error message to the Account Holder. 9. The
card is returned to the user.
Use Case Deposit Main Scenario 1. Include
Validate. 2. The Account Holder selects
Deposit. 3. The system retrieves the account
information and prompts Account Holder for amount
to deposit. 4. The Account Holder enters the
amount. 5. The system starts the deposit slot
mechanism. 6. The Account Holder places the
deposit item into the deposit slot mechanism. 7.
The system detects the deposit item and stops the
deposit slot mechanism. 8. The system adds the
deposit amount to the account. 9. The card is
returned to the Account Holder. Alternative
Deposit Slot Mechanism Fails to Start 5. The
system fails to start the deposit slot
mechanism. 6. The system displays an error
message to the Account Holder. 7. The card is
returned to the Account Holder. Alternative
Deposit Slot Mechanism Times Out 6. The Account
Holder does not place the deposit item in the
deposit slot mechanism within 5 seconds. 7. The
system did not detect a deposit item and stops
the deposit slot mechanism 8. The system displays
an error message to the Account Holder. 9. The
card is returned to the user.
Extension may deviate at a predefined location.
Use Case Deposit Extends Deposit Main
Scenario Replace XP with 1. The system fails to
start the deposit slot mechanism. 2. The system
displays an error message to the Account
Holder. 3. The card is returned to the Account
Holder.
27Use Case Diagrams Extend Relationship
ATM
ltltincludegtgt
Check Balance
Deposit XP1
ltltextendgtgt(XP1)
Deposit Slot Mechanism Failure
Account Holder
28Activity
- Using the use cases from the previous activities,
identify any uses of the extend relationships - Elaborate two use cases involved in an extend
relationship - Force one if necessary
29Use Cases Generalization / Specialization
Relationship
- Similar to extending a use case, we can
specialize a use case - Specialization of a use case is similar to
extending but does not require explicit extension
points - Child specializes the parent
- Parent is a generalization of the child
30Use Cases Diagrams Generalization /
Specialization Relationship
31Use Cases Diagrams Generalization /
Specialization Relationship
Specific
General
32Use Cases Generalization vs Extension
Extensions represents a controlled deviation.
Extensions represents a controlled deviation.
A XP
Generalizations represent uncontrolled deviation.
B may only deviate from A at the point XP1.
ltltextendgtgt (XP)
A
B
B may deviate from A in any imaginable way. In
fact, it is possible that B may not look anything
like A!
B
33Discussion
- Why do we need both generalization and extend?
- What would be appropriate uses of each?
34Use Cases Diagrams Putting it all together
- Use Case diagrams can capture multiple use cases
ATM
Withdraw
ltltincludegtgt
ltltincludegtgt
Check Balance
Validate
Deposit XP
ltltincludegtgt
Account Holder
ltltextendgtgtXP
Run Diagnositcs
Deposit Slot Mechanism Failure
Technician
35Using Visio
- Visio is a generic drawing tool
- You dont need it
- We use it in this class for experience
- UML stencils are available
- Software UML Diagrams
- The stencils are out of date
- Use generic drawing tools to overcome