intellagile copyright © 2002 craig larman. all rights reserved. writing use cases: requirements in...

35
IntellAgile www.craiglarman.com Copyright © 2002 Craig Larman. All rights reserved. Writing Use Writing Use Cases: Cases: Requirements Requirements in Context in Context

Upload: agatha-hubbard

Post on 17-Dec-2015

214 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: IntellAgile  Copyright © 2002 Craig Larman. All rights reserved. Writing Use Cases: Requirements in Context

IntellAgile

www.craiglarman.comCopyright © 2002 Craig Larman. All rights reserved.

Writing Use Writing Use Cases:Cases:

Requirements Requirements in Contextin Context

Page 2: IntellAgile  Copyright © 2002 Craig Larman. All rights reserved. Writing Use Cases: Requirements in Context

2

IntellAgile DEFINITION: Use CaseDEFINITION: Use Case

Informally, a Informally, a use case use case is a story of using a is a story of using a system to fulfill a goal.system to fulfill a goal. Rent VideosRent Videos

Used by Used by primary actorsprimary actors E.g., ClerkE.g., Clerk External agentsExternal agents something with behaviorsomething with behavior

Use Use supporting actorssupporting actors. . CreditAuthorizationSystemCreditAuthorizationSystem

iterative requirements use cases sys. sequence diagrams domain models

Page 3: IntellAgile  Copyright © 2002 Craig Larman. All rights reserved. Writing Use Cases: Requirements in Context

3

IntellAgile EXAMPLE: Use Case. DEFINITION: BriefEXAMPLE: Use Case. DEFINITION: Brief

Here’s one in a Here’s one in a brief formatbrief format::

Rent VideosRent Videos. A Customer arrives with . A Customer arrives with videos to rent. The Clerk enters their ID, videos to rent. The Clerk enters their ID, and each video ID. The System outputs and each video ID. The System outputs information on each. The Clerk requests information on each. The Clerk requests the rental report. The System outputs it, the rental report. The System outputs it, which is given to the Customer with their which is given to the Customer with their videos.videos.

iterative requirements use cases sys. sequence diagrams domain models

Page 4: IntellAgile  Copyright © 2002 Craig Larman. All rights reserved. Writing Use Cases: Requirements in Context

4

IntellAgile DEFINITION: ScenarioDEFINITION: Scenario

Informally, a Informally, a scenarioscenario is a specific sequence is a specific sequence of actions and interactions in a use case.of actions and interactions in a use case. One path through the use case.One path through the use case. E.g., The scenario of renting videos and E.g., The scenario of renting videos and

first having to pay overdue fines.first having to pay overdue fines.

More formally, a More formally, a use caseuse case is a collection of is a collection of success and failure scenarios describing a success and failure scenarios describing a primary actor using a system to support a primary actor using a system to support a goal.goal.

iterative requirements use cases sys. sequence diagrams domain models

Page 5: IntellAgile  Copyright © 2002 Craig Larman. All rights reserved. Writing Use Cases: Requirements in Context

5

IntellAgile Use CasesUse Cases

There is nothing object-oriented about use There is nothing object-oriented about use cases. cases.

So, why bother in an OOA/D workshop?So, why bother in an OOA/D workshop? We need some kind of requirements input We need some kind of requirements input

for the design steps.for the design steps.

They are common/popular.They are common/popular.

There is a UML-related topic.There is a UML-related topic.– Use case diagramsUse case diagrams

iterative requirements use cases sys. sequence diagrams domain models

Page 6: IntellAgile  Copyright © 2002 Craig Larman. All rights reserved. Writing Use Cases: Requirements in Context

6

IntellAgile Levels of Use CasesLevels of Use Cases

A common challenge is A common challenge is identifying use cases at identifying use cases at a useful goal level.a useful goal level.

For example, how do For example, how do we know which of these we know which of these is at a useful level?is at a useful level?

Negotiate a Supplier Negotiate a Supplier ContractContract

Rent VideosRent Videos Log InLog In Start UpStart Up

iterative requirements use cases sys. sequence diagrams domain models

Page 7: IntellAgile  Copyright © 2002 Craig Larman. All rights reserved. Writing Use Cases: Requirements in Context

7

IntellAgile Levels of Use CasesLevels of Use Cases

One answer is that they One answer is that they are all use cases.are all use cases.

Not helpful…Not helpful…

We can end up with We can end up with too many fine-grain too many fine-grain use casesuse cases– management and management and

complexity problems.complexity problems.

Or “fat” use cases Or “fat” use cases which span an entire which span an entire organization.organization.

iterative requirements use cases sys. sequence diagrams domain models

Page 8: IntellAgile  Copyright © 2002 Craig Larman. All rights reserved. Writing Use Cases: Requirements in Context

8

IntellAgile GUIDELINES: EBP for Use Case LevelsGUIDELINES: EBP for Use Case Levels Cockburn supports the Cockburn supports the

Elementary Business Elementary Business Process (EBP) Process (EBP) guideline.guideline.

Focus on use cases at Focus on use cases at the level of EBPs.the level of EBPs. ““A task performed A task performed

by one person in by one person in one place at one one place at one time, in response to time, in response to a business event, a business event, which adds which adds measurable measurable business value and business value and leaves the data in a leaves the data in a consistent state.”consistent state.”

iterative requirements use cases sys. sequence diagrams domain models

Page 9: IntellAgile  Copyright © 2002 Craig Larman. All rights reserved. Writing Use Cases: Requirements in Context

9

IntellAgile GUIDELINES: EBP for Use Case LevelsGUIDELINES: EBP for Use Case Levels

Naively, can you apply Naively, can you apply the “boss test” for an the “boss test” for an EBP?EBP?

Boss: “What do you do Boss: “What do you do all day?”all day?”

Me: “I logged in!”Me: “I logged in!”

Is Boss happy?Is Boss happy?

iterative requirements use cases sys. sequence diagrams domain models

Page 10: IntellAgile  Copyright © 2002 Craig Larman. All rights reserved. Writing Use Cases: Requirements in Context

10

IntellAgile GUIDELINES: Size for Use Case LevelsGUIDELINES: Size for Use Case Levels

An EBP-level use case An EBP-level use case usuallyusually is composed of is composed of several steps, not just several steps, not just one or two.one or two.

It isn’t a single step.It isn’t a single step.

iterative requirements use cases sys. sequence diagrams domain models

Page 11: IntellAgile  Copyright © 2002 Craig Larman. All rights reserved. Writing Use Cases: Requirements in Context

11

IntellAgile Use Case Levels: Applying the GuidelinesUse Case Levels: Applying the Guidelines

Applying the EBP and Applying the EBP and size guidelines:size guidelines:

Negotiate a Supplier Negotiate a Supplier ContractContract

Rent VideosRent Videos Log InLog In Start UpStart Up

The others The others cancan also be also be modeled as use cases. modeled as use cases. But, prefer a focus But, prefer a focus

on the EBP level. on the EBP level.

iterative requirements use cases sys. sequence diagrams domain models

Page 12: IntellAgile  Copyright © 2002 Craig Larman. All rights reserved. Writing Use Cases: Requirements in Context

12

IntellAgile Use Case DiagramsUse Case Diagrams

The UML has use case diagrams.The UML has use case diagrams.

Use cases are Use cases are texttext, not diagrams., not diagrams. Use case analysis is a Use case analysis is a writingwriting effort, not effort, not

drawing.drawing.

But a But a shortshort time drawing a use case diagram time drawing a use case diagram provides a context for:provides a context for: identifying use cases by nameidentifying use cases by name creating a “context diagram”creating a “context diagram”

iterative requirements use cases sys. sequence diagrams domain models

Page 13: IntellAgile  Copyright © 2002 Craig Larman. All rights reserved. Writing Use Cases: Requirements in Context

13

IntellAgile Use Case DiagramsUse Case Diagrams

iterative requirements use cases sys. sequence diagrams domain models

Video StoreInformation System

Administrator

ManageInventory

ManageMemberships

Clerk

Customer

«actor»Credit

AuthorizationService

Pay Fines

Rent Items

Log In

Manage Users

Warning: Don’t spend much time on diagramming.

Use case work means to write text, not draw

diagrams

Page 14: IntellAgile  Copyright © 2002 Craig Larman. All rights reserved. Writing Use Cases: Requirements in Context

14

IntellAgile GUIDELINES: Use Case DiagramsGUIDELINES: Use Case Diagrams

iterative requirements use cases sys. sequence diagrams domain models

Video Store Information System

Rent Videos

. . .Clerk

Show computer system actorswith an alternate notation tohuman actors.

primary actors onthe left

supporting actorson the right

Prefer use cases at the EBP level.

«actor»Credit

AuthorizationService

Page 15: IntellAgile  Copyright © 2002 Craig Larman. All rights reserved. Writing Use Cases: Requirements in Context

15

IntellAgile GUIDELINES: Use Case DiagramsGUIDELINES: Use Case Diagrams

Types of ActorsTypes of Actors

Primary actor – has goal, initiates taskPrimary actor – has goal, initiates task

Supporting actor – involved in dialogue, provide Supporting actor – involved in dialogue, provide services or informationservices or information

Off-stage actor – has an interest in the use caseOff-stage actor – has an interest in the use case

iterative requirements use cases sys. sequence diagrams domain models

Page 16: IntellAgile  Copyright © 2002 Craig Larman. All rights reserved. Writing Use Cases: Requirements in Context

16

IntellAgile GUIDELINES: Use Case ModelingGUIDELINES: Use Case Modeling

It is common to group CRUD (Create, Read, It is common to group CRUD (Create, Read, Update, Delete) operations into one use Update, Delete) operations into one use case.case.

Manage UsersManage Users

Name starts with a verb.Name starts with a verb. Manage Manage UsersUsers

All systems have a All systems have a Start UpStart Up and and Shut DownShut Down use case (perhaps trivial and low level).use case (perhaps trivial and low level).

But sometimes, important.But sometimes, important.– an avionics systeman avionics system

iterative requirements use cases sys. sequence diagrams domain models

Page 17: IntellAgile  Copyright © 2002 Craig Larman. All rights reserved. Writing Use Cases: Requirements in Context

17

IntellAgile GUIDELINES: Use Case ModelingGUIDELINES: Use Case Modeling

Prefer EBP-level use cases.Prefer EBP-level use cases. AKA AKA user-level goaluser-level goal use cases. use cases.

Common quality assurance checks. Are Common quality assurance checks. Are these present:these present:

Use Cases:Use Cases:– Some variant of Some variant of Configure SystemConfigure System– Sometimes, Sometimes, Start UpStart Up and and Shut DownShut Down

Actors:Actors:– System AdministratorSystem Administrator

iterative requirements use cases sys. sequence diagrams domain models

Page 18: IntellAgile  Copyright © 2002 Craig Larman. All rights reserved. Writing Use Cases: Requirements in Context

18

IntellAgile Detail in Use CasesDetail in Use Cases

Iterative writing of use cases: idea, basics, Iterative writing of use cases: idea, basics, scenarios, fully dressed descriptionscenarios, fully dressed description

““brief” format = terse one-paragraph summarybrief” format = terse one-paragraph summary

““casual” format = one informal paragraph per casual” format = one informal paragraph per scenarioscenario

““fully dressed” format = everything you wantfully dressed” format = everything you want

iterative requirements use cases sys. sequence diagrams domain models

Page 19: IntellAgile  Copyright © 2002 Craig Larman. All rights reserved. Writing Use Cases: Requirements in Context

19

IntellAgile DEFINITION: Fully Dressed Use CasesDEFINITION: Fully Dressed Use Cases

Rich notation for detailed analysis.Rich notation for detailed analysis.

Shows branching scenarios.Shows branching scenarios.

Can include non-functional requirements Can include non-functional requirements related to the functional.related to the functional.

iterative requirements use cases sys. sequence diagrams domain models

Page 20: IntellAgile  Copyright © 2002 Craig Larman. All rights reserved. Writing Use Cases: Requirements in Context

20

IntellAgile EXAMPLE: Fully DressedEXAMPLE: Fully Dressed

Use Case UC1Use Case UC1: Rent Video: Rent VideoLevel:Level: User-level goal (EBP level) User-level goal (EBP level)   Primary ActorPrimary Actor: Clerk: ClerkPreconditionsPreconditions: : Clerk is identified and authenticated.Clerk is identified and authenticated.

Stakeholders and their InterestsStakeholders and their Interests::Clerk: Wants accurate, fast entry.Clerk: Wants accurate, fast entry.CustomerCustomer: Wants videos, and fast service with minimal : Wants videos, and fast service with minimal

effort. effort. AccountantAccountant: Wants to accurately record transactions.: Wants to accurately record transactions.MarketingMarketing: Wants to track customer habits.: Wants to track customer habits.. . .. . .

iterative requirements use cases sys. sequence diagrams domain models

Page 21: IntellAgile  Copyright © 2002 Craig Larman. All rights reserved. Writing Use Cases: Requirements in Context

21

IntellAgile EXAMPLE: Fully DressedEXAMPLE: Fully DressedMain Success Scenario (or Basic Flow or “Happy Path”)Main Success Scenario (or Basic Flow or “Happy Path”)::

1.1. Customer arrives at a checkout with videos or games to rent.Customer arrives at a checkout with videos or games to rent.

2.2. Clerk enters Customer ID.Clerk enters Customer ID.

3.3. Clerk enters rental identifier. Clerk enters rental identifier.

4.4. System records rental line item and presents item description.System records rental line item and presents item description.

(Clerk repeats steps 3-4 until indicates done.)(Clerk repeats steps 3-4 until indicates done.)

5.5. System displays total. System displays total.

6.6. Customer pays. System handles payment.Customer pays. System handles payment.

7.7. Clerk requests rental report.Clerk requests rental report.

8.8. System outputs it. Clerk gives it to Customer.System outputs it. Clerk gives it to Customer.

9.9. Customer leaves with rentals and report.Customer leaves with rentals and report.

iterative requirements use cases sys. sequence diagrams domain models

Page 22: IntellAgile  Copyright © 2002 Craig Larman. All rights reserved. Writing Use Cases: Requirements in Context

22

IntellAgile EXAMPLE: Fully DressedEXAMPLE: Fully DressedExtensions (or Alternatives)Extensions (or Alternatives)::

a*. At any time, System fails:a*. At any time, System fails:1.1. Clerk restarts SystemClerk restarts System2.2. logs inlogs in3.3. requests recovery from prior staterequests recovery from prior state

1a. New Customer.1a. New Customer.

1. Perform use case 1. Perform use case Manage MembershipManage Membership..

2a. Customer ID not found.2a. Customer ID not found.

1. Cashier verifies ID. If entry error, reenter, else 1. Cashier verifies ID. If entry error, reenter, else Manage Manage MembershipMembership..

2b. Customer has unpaid fines (usually for late returns).2b. Customer has unpaid fines (usually for late returns).

1. 1. Pay FinesPay Fines..

iterative requirements use cases sys. sequence diagrams domain models

Page 23: IntellAgile  Copyright © 2002 Craig Larman. All rights reserved. Writing Use Cases: Requirements in Context

23

IntellAgile EXAMPLE: Fully DressedEXAMPLE: Fully DressedSpecial RequirementsSpecial Requirements:: Language internationalization on the display messages and Language internationalization on the display messages and

rental report.rental report. Large text on display. Visible from 1 m.Large text on display. Visible from 1 m.

Technology and Data VariationsTechnology and Data Variations:: ID entries by bar code scanner or keyboard.ID entries by bar code scanner or keyboard.

FrequencyFrequency:: Near continuousNear continuous

Open IssuesOpen Issues:: Should we support a magnetic stripe cards for customer ID, Should we support a magnetic stripe cards for customer ID,

and allow customer to directly use card reader?and allow customer to directly use card reader?

iterative requirements use cases sys. sequence diagrams domain models

Page 24: IntellAgile  Copyright © 2002 Craig Larman. All rights reserved. Writing Use Cases: Requirements in Context

24

IntellAgile USE CASES: non-functional requirementsUSE CASES: non-functional requirements

Note that use cases can capture non-functional Note that use cases can capture non-functional requirementsrequirements

Performance: indicate performance constraints Performance: indicate performance constraints on individual scenarioson individual scenarios

Security: indicate which tasks must be secureSecurity: indicate which tasks must be secure

Usability: indicate user characteristics with Usability: indicate user characteristics with actor definitions; indicate frequency of user actor definitions; indicate frequency of user events with use case, …events with use case, …

Portability, etc: These are “developer” use Portability, etc: These are “developer” use cases, not “user” use casescases, not “user” use cases

iterative requirements use cases sys. sequence diagrams domain models

Page 25: IntellAgile  Copyright © 2002 Craig Larman. All rights reserved. Writing Use Cases: Requirements in Context

25

IntellAgile DEFINITION: Essential & Concrete Use CasesDEFINITION: Essential & Concrete Use Cases

““Keep the UI out”Keep the UI out”

EssentialEssential use cases defer the details of the use cases defer the details of the UI, and focus on the UI, and focus on the intentionsintentions of the actors. of the actors.

EssentialEssential: Clerk enters Customer ID.: Clerk enters Customer ID.

Concrete/worseConcrete/worse: Clerk takes Customer ID : Clerk takes Customer ID card and reads the bar code with laser card and reads the bar code with laser scanner.scanner.

iterative requirements use cases sys. sequence diagrams domain models

Page 26: IntellAgile  Copyright © 2002 Craig Larman. All rights reserved. Writing Use Cases: Requirements in Context

26

IntellAgile GUIDELINES: Use Case WritingGUIDELINES: Use Case Writing

Start sentence 1 with “<Actor> does Start sentence 1 with “<Actor> does <event>”<event>”

Customer arrives with videos to rent.Customer arrives with videos to rent.

First write in the essential form, and “Keep First write in the essential form, and “Keep the UI out.”the UI out.”

Capitalize “actor” names.Capitalize “actor” names.1.1. ……2.2. ClerkClerk enters… enters…3.3. SystemSystem outputs… outputs…

iterative requirements use cases sys. sequence diagrams domain models

Page 27: IntellAgile  Copyright © 2002 Craig Larman. All rights reserved. Writing Use Cases: Requirements in Context

27

IntellAgile GUIDELINES: Use Case WritingGUIDELINES: Use Case Writing

Terse is good. People don’t like reading Terse is good. People don’t like reading requirements ;). Avoid noisy words.requirements ;). Avoid noisy words.

More verboseMore verbose1.1. ……2.2. The Clerk enters…The Clerk enters…3.3. The System outputs…The System outputs…

LessLess1.1. ……2.2. ClerkClerk enters… enters…3.3. SystemSystem outputs… outputs…

iterative requirements use cases sys. sequence diagrams domain models

Page 28: IntellAgile  Copyright © 2002 Craig Larman. All rights reserved. Writing Use Cases: Requirements in Context

28

IntellAgile GUIDELINES: Types of ScenariosGUIDELINES: Types of Scenarios

Main scenarioMain scenario

Alternative scenario – other ways of achieving Alternative scenario – other ways of achieving the goalthe goal

Exceptional scenario – where something goes Exceptional scenario – where something goes wrongwrong

Recovery scenario – but we can recoverRecovery scenario – but we can recover

Failure scenario – alas, we cannot recoverFailure scenario – alas, we cannot recover

NB For Larman, “failure scenario” = NB For Larman, “failure scenario” = “exceptional scenario”“exceptional scenario”

iterative requirements use cases sys. sequence diagrams domain models

Page 29: IntellAgile  Copyright © 2002 Craig Larman. All rights reserved. Writing Use Cases: Requirements in Context

29

IntellAgile MOTIVATION: Comprehensible & FamiliarMOTIVATION: Comprehensible & Familiar

Use cases are stories.Use cases are stories.

A simple and familiar A simple and familiar model that many model that many people, especially non-people, especially non-technical, can easily technical, can easily relate to.relate to.

iterative requirements use cases sys. sequence diagrams domain models

Page 30: IntellAgile  Copyright © 2002 Craig Larman. All rights reserved. Writing Use Cases: Requirements in Context

30

IntellAgile MOTIVATION: “Requirements in Context”MOTIVATION: “Requirements in Context”

The subtitle makes an The subtitle makes an important point:important point:

Use cases bring Use cases bring together related together related requirements.requirements.

More cohesion and More cohesion and context for related context for related requirements.requirements.

iterative requirements use cases sys. sequence diagrams domain models

Page 31: IntellAgile  Copyright © 2002 Craig Larman. All rights reserved. Writing Use Cases: Requirements in Context

31

IntellAgile Concrete Use CasesConcrete Use Cases

Sometime after the essential form of the use Sometime after the essential form of the use case has been written, one may case has been written, one may optionallyoptionally write it in a concrete form.write it in a concrete form.

1.1. Customer arrives at a checkout with videos Customer arrives at a checkout with videos or games to rent.or games to rent.

2.2. Clerk Clerk scansscans Customer ID… Customer ID…

ExtensionsExtensions

2a. Scanner failed.2a. Scanner failed.

1. Clerk enters ID on keyboard (see GUI 1. Clerk enters ID on keyboard (see GUI window example, fig 5)…window example, fig 5)…

Page 32: IntellAgile  Copyright © 2002 Craig Larman. All rights reserved. Writing Use Cases: Requirements in Context

32

IntellAgile Artifacts in the UP Use-Case ModelArtifacts in the UP Use-Case Model

iterative requirements use cases sys. sequence diagrams domain models

Requirements

Partial artifacts, refined in each iteration.

Use-Case Model

textuse

cases

:System

foo( x )

systemoperationcontracts

systemsequencediagrams

bar( y )

usecase

diagrams

systemoperations

Page 33: IntellAgile  Copyright © 2002 Craig Larman. All rights reserved. Writing Use Cases: Requirements in Context

33

IntellAgile Artifacts in the UP Use-Case ModelArtifacts in the UP Use-Case Model

iterative requirements use cases sys. sequence diagrams domain models

Operation: enterItem(…)

Post-conditions:- . . .

Operation Contracts

Sale

date. . .

SalesLineItem

quantity

1..*1 . . .

. . .

Domain Model

Use-Case Model

Design Model: Register

enterItem(itemID, quantity)

: ProductCatalog

spec = getProductSpec( itemID )

addLineItem( spec, quantity )

: Sale

objects, attributes, associations

Require-ments

Business Modeling

Design

Sample UP Artifact Relationships

: System

enterItem(id, quantity)

Use Case Text

System Sequence Diagrams

makeNewSale()

system events

Cashier

Process Sale

: Cashier

use case

names

system operations

Use Case Diagram

Vision

SupplementarySpecification

Glossary

scope, goals, actors, features

terms, attributes, validation

non-functional reqs, quality attributes

requirements

Process Sale

1. Customer arrives ...2. Cashier makes new sale.3. ...

Page 34: IntellAgile  Copyright © 2002 Craig Larman. All rights reserved. Writing Use Cases: Requirements in Context

34

IntellAgile Context – Organisational Context – Organisational

iterative requirements use cases sys. sequence diagrams domain models

Goal: Process sales

Cashier

Customer

POS System

Checkout Service

Goal: Buy items

Enterprise Selling Things

Sales TaxAgency

Goal: Collect taxes on sales Sales Activity

System

Goal: Analyze sales and performance data

Page 35: IntellAgile  Copyright © 2002 Craig Larman. All rights reserved. Writing Use Cases: Requirements in Context

35

IntellAgile Context – System Subsystem Context – System Subsystem

User-level use casesUser-level use cases

User work tasksUser work tasks

User goals for taskUser goals for task

(External) actor-system (External) actor-system dialoguedialogue

Target system being Target system being modeled is the whole modeled is the whole systemsystem

But … can model use But … can model use cases of a subsystem …cases of a subsystem …

Subsystem as target Subsystem as target systemsystem

Means other subsystems Means other subsystems are actors external to are actors external to the subsystemthe subsystem

Means that a client of the Means that a client of the service of the subsystem service of the subsystem is an actor (client is is an actor (client is another subsystem …)another subsystem …)

Still have tasks, goals, Still have tasks, goals, scenarios, etcscenarios, etc

Can construct a use case Can construct a use case modelmodel iterative requirements use cases sys. sequence diagrams

domain models