Académique Documents
Professionnel Documents
Culture Documents
1 Use Cases
Read Chapters 7 and 8 of Using UML
Issue: How do we systematically capture requirements?
Just asking stakeholders will produce random coverage of a domain.
Use Cases Centric approach provides a mechanism for systematically
capturing large related segments of domain requirements from the users
perspective in the form of scenarios. Most stakeholders know how they
interact or will interact with a system, or what needs a system must satisfy.
By capturing large related chunks of specification, we are less likely to miss
significant parts than we would be by dealing with individual requirements.
If we have the large chunks it is easy to fill in the missing gaps.
Use Cases modeling helps in more than four ways
1. Capturing requirements
2. Planning iterative development
3. Validating systems
4. Verifying systems
Developed by Ivar Jacobson
1.1.1
Two components , Actors and Use Cases. See Figure 7.2 on page 94
Actors:
Represented by stick people in the model
Someone or something that the system interacts with. Can be a person,
another system, but generally NOT a group.
Has a role in or with the use case
Identifying human actors:
o Dont specify individuals, but the roles they play in the domain
Example: dont use Bubba, but use Bubbas role as a Bank
Customer.
o Roles each unique actor role is represented by an Actor even if the
different roles are played by the same individual.
Page 1
09/19/2011 12:00 PM
Use
Non-human actors: allows abstraction of other systems that interact with our
system. This simplifies the model, in that we dont need to get into the details
of other systems.
Case
Represented by an oval in the model.
A use case represents a sequence of actions or steps a system performs
that yields an observable result of value to a particular actor.
An action is a procedure that is invoked when an actor provides a signal to
the system or when the system is triggered (example a time out occurs). An
action is atomic it is performed entirely or not at all.
Use verb phases to name Use Cases (WithdrawMoney, CheckoutBook,
OrderPizza, EatLunch, TakeOutTheGarbage, etc.) Do not use nouns
(Withdrawal, Book Checkout, Pizza Order, Lunch, )
Scope of a Use Case can be controlled by the following guidelines:
An observable result of value an actor should not need to perform
several use cases to achieve something useful.
o This provides guidance for keeping the level of granularity high
enough.
o Example1: Entering ones PIN in an ATM machine does not
provide something meaningful to the actor, an ATM Bank
Customer who is withdrawing money.
o Example2: Taking a picture with a camera ( aiming, focusing,
clicking the button) is at a good level in that it produces
something of value for the Actor, whereas just clicking the button
of the camera (alone) is not sufficient.
A particular actor forces the value of a use case to be relevant to a
specific user or small class of users.
o This provides guidance for keeping the level of granularity low
enough.
o Example: A Use Case should not include all transactions of an
ATM machine (WithdrawMoney, PayBills, PayLoan, BuyStocks, )
as most Actor instances will never use all of these use cases.
Page 2
09/19/2011 12:00 PM
Page 3
09/19/2011 12:00 PM
Capture the details of WHAT a use case should do. Use cases can replace lowlevel requirements or augment low-level requirements by showing how they
function altogether.
A scenario defines a process from the users point of view.
Written in concise steps from a users / actors perspective.
Domain terms must be consistently defined in the project glossary.
Example: Withdraw Money from an ATM (Note: I have capitalized Actor
Names)
1. The use case begins when the Client inserts an ATM card.
2. The System reads the information on the ATM card
3. The System validates the information read from the ATM card.
4. The System prompts for PIN.
5. The Client enters PIN.
6. The System validates PIN.
7. The System asks which operation the Client wishes to perform.
8. The Client selects Cash withdrawal
9. The System prompts for the amount to withdraw.
10. The Client enters amount
11. The System displaces account types (checking, saving,
credit) and requests the Client select one for withdrawal
12. The Client selects the account type
13. The System communicates with the ATM network to validate
account ID, PIN, and availability of the amount requested.
14. The System asks the Client whether he/she wants a receipt.
15. The System asks the Client to withdraw the card. (This is a
security measure to ensure that Clients do not leave their cards in
the machine.)
16. The Client withdraws the card.
17. The System dispenses the requested amount of cash.
18. The System prints a receipt.
19. The Client pulls out the receipt.
There are various paths through this use case based on
o Input from the Client: (can cancel at anytime, want a receipt, which
account, etc.)
o Internal state of the System: (out of paper for receipt, too little cash in ATM,
etc.)
o Time-outs and errors: (System may cancel transaction on a timeout for
Client action, network response, repeated wrong PIN, bad ATM card, etc.)
o Each instance, represents unique path, and is called a Use Case Scenario.
The set of all scenarios is a use case (class).
o Sunny Day Scenario term used to refer to the primary, everything goes
smooth, path through a use case.
Page 4
09/19/2011 12:00 PM
1.2.1
What is too little and what is too much for a single use case.
o We could combine all ATM transactions into a single use case (Withdraw,
Deposit, Transfer, Pay Loan, etc.).
This would provide multiple observable results for an actor,
therefore not a good idea.
Also, subclasses of actors may never use all of these transactions.
Has anyone used the Pay Loan use case?
This is too large!
o We could break the Withdraw use case into multiple use cases, Read Pin,
Validate Pin, but each of these alone do not provide an observable of
result of any real value to any actor.
This is too small.
o Focus on finding things of value that a system provides to its actors
How detailed should the steps be?
o Until there is agreement among stakeholders (users, testers, designers,
developers, etc.) with respect to what a use case means.
Organization of Use Cases Some huge systems may have 1000s of use
cases.
Biggest system I worked on probably approached around 5,000
use cases.
There were about 50 subsystems each with about 100 use cases.
o Use Case Package in larger systems one needs to group similar use
cases together to help people access and analyze them. Systems,
Subsystems, Subsubsystems, seem to provide natural container
boundaries.
Usually a good size range in package will have from 5-20 Use
Cases.
Packages can contain other Packages.
o Subflows A main use case may be subdivided into several
(alternative) subflows. This is generally done when the same set of
steps is common to multiple main use cases. The concept is similar to a
reusable function/procedure in a programming language.
UML 1.3 had two constructs for subflows, Uses and Extends .
Uses common steps that are ALWAYS executed in one or
more use cases. Simply done for reuse of common concepts
(code, doc, tests, ). EX: StartATM_Session, ReadCard,
and EnterAndValidatePIN are common to all ATM functions
(Withdraw, Deposit, Transfer, PayLoan, etc.). We could make
a Uses use case of UserAuthentication.
Page 5
09/19/2011 12:00 PM
Page 6
09/19/2011 12:00 PM
Make sure that each use case produces at least one obvious result of
value to one or more actors, even if that result is negative.
o A use case cant just end floating in spacesomething measurable has
to happen. Of course, this is generally some positive result: The actor is
logged in to the system, The system creates an Order, The system
generates a report.
o Some like to specify this as a postcondition dont do it in both the last
step of a use case and in a postcondition (this would be redundant).
Write your alternate courses rainy day scenarios the same way you
write your basic course, except of course that alternates have the
word if.
o Signal the presence of an alternate course involves using words such as
validates, verifies, ensures, or checks.
The system verifies that the credit card number the Customer
entered matches one of the numbers it has recorded for that
Customer, this begs the question Well what happens if the
verification fails?
Page 7
09/19/2011 12:00 PM
If the system does not match the entered credit card number to
any of its stored values, then it displays an error message and
prompts the Customer to enter a different number.
Page 8
09/19/2011 12:00 PM
Page 9
Within
Scope**
NO
YES
YES
YES
Maintenanc
e
subsystem
09/19/2011 12:00 PM
AuthorizeATM_Custome 1
r
Open new bank
accounts
Transactions
User selected
Security
subsystem
NO
...
** For large Systems, use the subsystem name for the Within Scope col.
The Task-Level Goal list can be very useful in:
Defining the scope of your current project,
Planning multiple iterations.
o For planning iterative phases, we can also concentrate on high priority
goals first.
o Sometime it makes sense to do some lower priority items first because
they will make other items easier to implement/test/
All stakeholders can quickly see the candidate goals for the system and
negotiate priorities. . .
ATM_Customer
(anotherBankCusto
mer)
09/19/2011 12:00 PM
RunBuiltInTest
(BIT)
A n o th e r B a n k 's
C u s to m e r
A T M M a c h in e
use cases
O u r B a n k s A T M C u s to m e r
A T M C o m m L in k
O th e r B a n k s
C en tral B an k
C o m p uter
o th er
ap p licatio n s
O u r B a n k 's C u s t o m e r
Page 11
09/19/2011 12:00 PM
Page 12
09/19/2011 12:00 PM
Page 13
09/19/2011 12:00 PM
Page 14
09/19/2011 12:00 PM
...
2.6 Collecting Data Requirements
It is often useful to collect data requirements as we develop our use cases.
Historically data dictionaries contained information about the type, range,
relationships and usage of data in a system. We may want to consider modifying
this approach. Keith Matthews (2006) published a set of ideas in the Requirements
Network Group http://www.requirementsnetwork.com/user_registration?
destination=trackerlite that with a little modification (by me) seems to provide good
utility. This new approach contains two different sets of tables.
2.6.1
While we are capturing use case flow, it is generally also a good time to capture
details about data entities. This will help all stakeholders come to a common
understanding of the data entities and the relationships among the entities. Below
are data that might be useful to capture at this time.
Category
Information Categories
Entity
Attributes
Associations
Page 15
09/19/2011 12:00 PM
Definition
Sensiti
ve
No
Type
Length
firstName
Text
25
No
Text
25
Yes
Yes
Text
Text
9
12
No
Text
Yes
Money
11.2
dateOfBirth
PIN
Yes
Yes
YYYYMMDD
nnnn
motherMaiden
Yes
Text
numeri
c
text
Relationships
marriedTo
Business Rule
A Customer may be married to zero or one
Spouse
A Customer may be the parent of zero, one or
more Child
A Customer may have one or more Accounts
A Customer is insured for up to a maximum
total across all Accounts of $1,000,000 by the
F.D.I.C.
lastName
SSN
driversLicenseNu
mber
driversLicenseSta
te
creditLimit
parrentOf
accountsOf
accountIssurance
Max
Entity / Type
Spouse
Description
A person to whom a Customer is
married.
Attributes
Definition
firstName
lastName
SSN
driversLicenseNu
mber
driversLicenseSta
te
24
Sensiti
ve
No
No
Yes
Yes
Type
Length
Text
Text
Text
Text
25
25
9
12
No
Text
09/19/2011 12:00 PM
Yes
Yes
dateOfBirth
motherMaiden
Yes
Yes
Relationships
marriedTo
Business Rule
A Spouse may be married to zero or one
Customer
A Spouse may be the parent of zero, one or
more Child
parrentOf
Entity / Type
Child
Description
A person who is legally classified as a
dependent of a Customer or Spouse
Attributes
Definition
firstName
lastName
schoolName
Sensiti
ve
Yes
Yes
Yes
Text
numeri
c
Text
text
YYYYMMDD
nnnn
YYYYMMDD
24
Type
Length
Text
Text
Text
25
25
25
2.6.2
CRUD Table
A CRUD (CreateReadUpdateDelete) Table defines at a high level where (by use case)
a data entity is used and how it is used (Created, Read, Updated, Deleted). It does
not get into the detail about the makeup of each entity. There is one CRUD table
per system. If we see that a data entity is missing any CRUD stage, then it is likely
that there is a gap in our use cases.
CRUD Table for a Star Wars-type computer game
Data
2011 Mike Rowe
Use Cases
Use
Page 17
Use Cases
Use Cases
09/19/2011 12:00 PM
--Created--
Defense
BuyDefense
GoldCoin
CalculatePlanetO
utput
Weapon
BuyWeapons
Populatio
n
...
Cases
--Read-DisplaySc
ore
BuyDefen
se
DisplaySc
ore
BuyWeapo
ns
DisplaySc
ore
...
--Updated--
--Deleted--
ExecuteEngage
ment
ExecuteEngade
ment
BuyDefense
BuyWeapons
BuyTechnology
...
BuyDefense
BuyWeapons
BuyTechnology
...
...
...
...
In this table we list the use cases that make use of each of the data entities and how
the use cases use the entities. This table helps us keep track of the data lifecycle
(creation through destruction) in a system.
2.6.3
The Detailed Entity Table maintains consistency in the data entities as we discover
how they are being used and are associated.
The CRUD table helps us keep track of the use of each of the entities. This is
important when we need to react to changes. If one use case changes, it may
require modifications to entities. In turn, the changes to an entity may cascade into
the other use cases that use that entity.
2.7.1
<<Uses>> or <<Includes>>
o Factor out common behavior from two or more main use cases
o Shown as a dashed line with an arrow pointing at the behavior that is factored
out (refactoring use cases) of the other use cases.
o The flow of an <<includes>> is ALWAYS executed. This will be a significant
difference between <<includes>> and the other factoring use cases.
2011 Mike Rowe
Page 18
09/19/2011 12:00 PM
o EX: Check out book and Extend loan may both use Check for reservation
Extend Loan
<<includes>
>
Check for
Reservations
<<includes>>
o The Check for reservations is also included in other use cases. The steps for
included use cases are factored out of the main use cases and a notation is
placed in the main use case flow to indicate the factoring. Then the Librarian
Actor checks to see if the book is already reserved. (See
UC_CheckForReservations).
Lets identify possible inclusions in the ATM machine.
Withdraw Money from an ATM
1. Customer inserts ATM card.
2. ATM runs BIT.
3. ATM reads information on the ATM card.
4. ATM validates information on the ATM card.
5. ATM displays prompts for PIN.
6. Customer enters PIN.
7. ATM validates PIN.
8. ATM displays prompt asking Which operation do you want to perform?
9. Customer selects Cash withdrawal
10.
ATM displays prompt for amount to withdraw.
11.
Customer enters amount
12.
ATM displays prompt requesting from which account to withdraw.
13.
Customer selects the account type (checking, saving, credit).
14.
ATM communicates with the ATM network to authorize user by validating
account ID, PIN, and availability of the amount requested.
15.
The ATM displays prompt asking the Customer whether he/she wants a
receipt.
16.
ATM asks the client to withdraw the ATM card.
Page 19
09/19/2011 12:00 PM
2.7.2
Can save further analysis and design work from this point on.
Only need to develop the functionality once.
Can share testing. Speeds validation walkthroughs. Only need to test it once
as code.
Can share documentation, this can be significant if functionality is visible to
users.
Indicates an early decision to reuse a component in particular parts. Need to
pay particular attention to this component so that the component will be
suitable for both instances.
Can make the main uses cases simpler by abstracting detailed parts out.
Can help refine project plan earlier. The more and earlier reuse is identified,
the less resources are needed in the project. Estimating the efforts required
for reused components is far easier that new work!
The above are more difficult to do using a requirements only approach instead
of use case centric approach.
2.7.3
Advantages of Inclusions:
Page 20
09/19/2011 12:00 PM
2.7.4
Summary of Inclusion
UC_CheckoutBook
Extension points:
UC_RefuseLoan
Page 21
<<extend>>
UC_RefusesLoan
09/19/2011 12:00 PM
Back
o
o
o
Generalization
o Use cases and Actors can be generalized or specialized.
o Example from library system
o Actors Journal Barrower is a specialization of a Book Barrower.
o Use Cases Checkout Journal is a specialization of Book Checkout
Checkout Book
Book Borrower
Checkout Journal
Journal Borrower
2.7.5
The system box only appears on the top-level diagram (remember that a typical
UML Use Case description will be composed of many diagrams and sub-diagrams),
2011 Mike Rowe
Page 22
09/19/2011 12:00 PM
Page 23
09/19/2011 12:00 PM
Page 24
09/19/2011 12:00 PM