Use Case Diagrams - Universitetet i...

50
Use Cases, Jan Pettersen Nytun, slide no. 1 Use Case Diagrams Contents - History - The Role of Use Cases - Graphical Notation - Use case scenario - Actor - System Boundary - Use Case Text - One Use Case Approach - Use Case relations - Include - Generalization - Extends - not part of curriculum

Transcript of Use Case Diagrams - Universitetet i...

Page 1: Use Case Diagrams - Universitetet i Agdergrimstad.uia.no/ikt413/year2012/presentations/pdf/2012-03c-UseCas… · Use Case Diagram - a Part of UML Use case diagrams are often drawn

Use Cases, Jan Pettersen Nytun, slide no. 1

Use Case Diagrams Contents

- History - The Role of Use Cases - Graphical Notation - Use case scenario - Actor - System Boundary - Use Case Text - One Use Case Approach - Use Case relations - Include - Generalization - Extends - not part of curriculum

Page 2: Use Case Diagrams - Universitetet i Agdergrimstad.uia.no/ikt413/year2012/presentations/pdf/2012-03c-UseCas… · Use Case Diagram - a Part of UML Use case diagrams are often drawn

Use Cases, Jan Pettersen Nytun, slide no. 2

Use Cases Were Introduced by Ivar Jacobson in the Beginning of the 1990s.

“A use case is a specific way of using the system by performing some part of the functionality. Each use case constitutes a complete course of events initiated by an actor, and it specifies the interaction that takes place between an actor and the system…... The collected use cases specify all the existing ways of using the system.”

Grady Booch et al. use case-based analysis: If you design a new house and you are reasoning about how you and

your family will use it, this is use case-based analysis. You consider the various ways in which you‘ll use the house, and these use cases drive the design afterwards.

Page 3: Use Case Diagrams - Universitetet i Agdergrimstad.uia.no/ikt413/year2012/presentations/pdf/2012-03c-UseCas… · Use Case Diagram - a Part of UML Use case diagrams are often drawn

Use Cases, Jan Pettersen Nytun, slide no. 3

Use Case Diagrams Contents

- History - The Role of Use Cases - Graphical Notation - Use case scenario - Actor - System Boundary - Use Case Text - One Use Case Approach - Use Case relations - Include - Generalization

- Extends - not part of curriculum

Page 4: Use Case Diagrams - Universitetet i Agdergrimstad.uia.no/ikt413/year2012/presentations/pdf/2012-03c-UseCas… · Use Case Diagram - a Part of UML Use case diagrams are often drawn

Use Cases, Jan Pettersen Nytun, slide no. 4

Use Case Diagram - a Part of UML Use case diagrams are often drawn in collaboration with users

of the system. In essence use case diagrams will show, from an external point of view, how the system will be used by the various users - how the dialog between users and the system will be.

Use case diagrams are often the kind of diagrams one starts out with, they may be part of the requirements modeling. Users of the system can easily identify with the diagrams, after all the diagrams identify interactions that users have with the system when they wants to achieve some goal. If use cases are used extensively they can drive the whole development process.

So the focus is: What functionality is involved and who will ask for the provided services. How the services are carried technically out by the system is not addressed.

With users we don’t necessarily mean humans, external systems which interacts with the system under consideration will also be modeled as a user (actor).

Page 5: Use Case Diagrams - Universitetet i Agdergrimstad.uia.no/ikt413/year2012/presentations/pdf/2012-03c-UseCas… · Use Case Diagram - a Part of UML Use case diagrams are often drawn

Use Cases, Jan Pettersen Nytun, slide no. 5

Purpose of Use Cases

• Capture the functional requirements of a system (what a system is supposed to do).

• Validating systems, a correct design allows all use cases to be carried out (each use case is realized). Drive implementation and generate test cases.

• Specify the context of a system.

Page 6: Use Case Diagrams - Universitetet i Agdergrimstad.uia.no/ikt413/year2012/presentations/pdf/2012-03c-UseCas… · Use Case Diagram - a Part of UML Use case diagrams are often drawn

Use Cases, Jan Pettersen Nytun, slide no. 6

Use Cases and Requirements

• A use case describes a unit of behavior. • A functional requirement describes a

law that governs behavior. • A use case can satisfy one or more

functional requirements. • A functional requirement may be

satisfied by one or more use cases.

Page 7: Use Case Diagrams - Universitetet i Agdergrimstad.uia.no/ikt413/year2012/presentations/pdf/2012-03c-UseCas… · Use Case Diagram - a Part of UML Use case diagrams are often drawn

Use Cases, Jan Pettersen Nytun, slide no. 7

Use Case Driven Development

• The focus will be on the user requirements (the use cases). • The use cases are the most important aspect of the design

process. • Use cases are used through the whole development

process, to track changes and define iterations. • Some see the examination of use cases as the main method

of finding classes and objects in the system, other recommend an approach where use cases and conceptual class diagrams are developed in parallel.

Page 8: Use Case Diagrams - Universitetet i Agdergrimstad.uia.no/ikt413/year2012/presentations/pdf/2012-03c-UseCas… · Use Case Diagram - a Part of UML Use case diagrams are often drawn

Use Cases, Jan Pettersen Nytun, slide no. 8

Some Possible Problems

• Use cases are not inherently object oriented, so we can end up with a non-object-oriented system.

• We might mistake design for requirements, e.g. specifying a sequence of interactions which in fact is only one of many sequence candidate to achieve the goal .

Page 9: Use Case Diagrams - Universitetet i Agdergrimstad.uia.no/ikt413/year2012/presentations/pdf/2012-03c-UseCas… · Use Case Diagram - a Part of UML Use case diagrams are often drawn

Use Cases, Jan Pettersen Nytun, slide no. 9

Use Case Refinement and Some Limitations

• It is possible to work top down, first specifying use cases at a high level and then proceed with more elaborated use case diagrams (use case refinement).

• Some limitations: – The interactions between objects inside the system are not modeled.

– You can not model concurrency.

Page 10: Use Case Diagrams - Universitetet i Agdergrimstad.uia.no/ikt413/year2012/presentations/pdf/2012-03c-UseCas… · Use Case Diagram - a Part of UML Use case diagrams are often drawn

Use Cases, Jan Pettersen Nytun, slide no. 10

Use Case Diagrams Contents

- History - The Role of Use Cases - Graphical Notation - Use case scenario - Actor - System Boundary - Use Case Text - One Use Case Approach - Use Case relations - Include - Generalization - Extends - not part of curriculum

Page 11: Use Case Diagrams - Universitetet i Agdergrimstad.uia.no/ikt413/year2012/presentations/pdf/2012-03c-UseCas… · Use Case Diagram - a Part of UML Use case diagrams are often drawn

Use Cases, Jan Pettersen Nytun, slide no. 11

Graphical Notation – An actor is a user role, a kind of stereotype. The actor is

symbolized with a “stick man” figure with the name of the actor below the figure.

actor

use case

Both actor and use case can initiate the communication.

actor

use case

The actor initiate the communication.

actor

use case

The use case initiate the communication.

– A use case is shown as an ellipse, with a name inside identifying the use case.

– When an actor is involved in a use case, a line is drawn from the actor to the use case. We say that the actor communicates with the use case. Who is initiating the communication can be indicated by an arrowhead.

Page 12: Use Case Diagrams - Universitetet i Agdergrimstad.uia.no/ikt413/year2012/presentations/pdf/2012-03c-UseCas… · Use Case Diagram - a Part of UML Use case diagrams are often drawn

Use Cases, Jan Pettersen Nytun, slide no. 12

Use Case Examples

student

register for course

works with course

lecturer

adm

lab

instructor

make/edit course

register for exam

register as student

System Boundary

Page 13: Use Case Diagrams - Universitetet i Agdergrimstad.uia.no/ikt413/year2012/presentations/pdf/2012-03c-UseCas… · Use Case Diagram - a Part of UML Use case diagrams are often drawn

Use Cases, Jan Pettersen Nytun, slide no. 13

Use Case Scenario • A use case is similar to a class, it represent a set of

possible interactions (a pattern, use case type).

• Different flows of events (scenarios) might be possible! A scenario is one possible interaction between the system an some actor(s).

• A scenario can be seen as an instance of a use case, in the same way as an object is seen as an instance of a class.

• Even if the scenarios are different for a use case, they all attempt to solve the same task!

Page 14: Use Case Diagrams - Universitetet i Agdergrimstad.uia.no/ikt413/year2012/presentations/pdf/2012-03c-UseCas… · Use Case Diagram - a Part of UML Use case diagrams are often drawn

Use Cases, Jan Pettersen Nytun, slide no. 14

[2] ”The total set of actors within a use case model reflects everything that needs to exchange information with the system.”

Actors are external to the system.

The Actor

Page 15: Use Case Diagrams - Universitetet i Agdergrimstad.uia.no/ikt413/year2012/presentations/pdf/2012-03c-UseCas… · Use Case Diagram - a Part of UML Use case diagrams are often drawn

Use Cases, Jan Pettersen Nytun, slide no. 15

[1] ”When you need to model things that happens to your system at a specific point in time but which don’t seem to be triggered by any actor, you can introduce an actor called Time... An example of this would be an automatic system backup that runs every evening.”

[1] Time as an Actor

Time

Page 16: Use Case Diagrams - Universitetet i Agdergrimstad.uia.no/ikt413/year2012/presentations/pdf/2012-03c-UseCas… · Use Case Diagram - a Part of UML Use case diagrams are often drawn

Use Cases, Jan Pettersen Nytun, slide no. 16

Actors and Class • It is common to have a class representing a

special type of actors (e.g. Student) inside the system.

• If you have a class representing a set of actors, you can mark this class with the stereotype ”actor”.

«actor» Student

Page 17: Use Case Diagrams - Universitetet i Agdergrimstad.uia.no/ikt413/year2012/presentations/pdf/2012-03c-UseCas… · Use Case Diagram - a Part of UML Use case diagrams are often drawn

Use Cases, Jan Pettersen Nytun, slide no. 17

System Boundary • With the help of use cases system

boundary can be defined.

• This is particular useful if you have a complex system and split it up into sub system. Specifying the boundaries of each subsystem can make the separation between the subsystem clear.

Page 18: Use Case Diagrams - Universitetet i Agdergrimstad.uia.no/ikt413/year2012/presentations/pdf/2012-03c-UseCas… · Use Case Diagram - a Part of UML Use case diagrams are often drawn

Use Cases, Jan Pettersen Nytun, slide no. 18

From the UML 2.0 Specification

Page 19: Use Case Diagrams - Universitetet i Agdergrimstad.uia.no/ikt413/year2012/presentations/pdf/2012-03c-UseCas… · Use Case Diagram - a Part of UML Use case diagrams are often drawn

Use Cases, Jan Pettersen Nytun, slide no. 19

A Use Case Is Often Described in Clear Text - But There are no UML Standard for Use Case

Specification

Example: Student register for course – Flow of events: The use case starts when the

student brows the course register page, inserts the student card in the card reader and issues the right pin code. The system presents all possible courses for this student. The student select course and commits the entry by pressing the Enter button.

– Alternative flow: The student can cancel a registration by pressing the Cancel button.

Page 20: Use Case Diagrams - Universitetet i Agdergrimstad.uia.no/ikt413/year2012/presentations/pdf/2012-03c-UseCas… · Use Case Diagram - a Part of UML Use case diagrams are often drawn

Use Cases, Jan Pettersen Nytun, slide no. 20

Some have: -(main) flow -alternative flow -exceptional flow flow

M1

M2

M3

M4

M5

M6

1A1

1A2 2A1

2A2

1E1 fail

Others have only main and alternative flow: ”An alternate course of action can represent an infrequently used path through the scenario, an exception, or an error condition.”

Page 21: Use Case Diagrams - Universitetet i Agdergrimstad.uia.no/ikt413/year2012/presentations/pdf/2012-03c-UseCas… · Use Case Diagram - a Part of UML Use case diagrams are often drawn

Use Cases, Jan Pettersen Nytun, slide no. 21

Use Case Diagrams Contents

- History - The Role of Use Cases - Graphical Notation - Use case scenario - Actor - System Boundary - Use Case Text - One Use Case Approach - Use Case relations - Include - Generalization

- Extends - not part of curriculum

Page 22: Use Case Diagrams - Universitetet i Agdergrimstad.uia.no/ikt413/year2012/presentations/pdf/2012-03c-UseCas… · Use Case Diagram - a Part of UML Use case diagrams are often drawn

Use Cases, Jan Pettersen Nytun, slide no. 22

“Use Case Form” from Together (Together is a modeling tool)

Page 23: Use Case Diagrams - Universitetet i Agdergrimstad.uia.no/ikt413/year2012/presentations/pdf/2012-03c-UseCas… · Use Case Diagram - a Part of UML Use case diagrams are often drawn

Use Cases, Jan Pettersen Nytun, slide no. 23

The Use Case Text can also be given in a note

Page 24: Use Case Diagrams - Universitetet i Agdergrimstad.uia.no/ikt413/year2012/presentations/pdf/2012-03c-UseCas… · Use Case Diagram - a Part of UML Use case diagrams are often drawn

Use Cases, Jan Pettersen Nytun, slide no. 24

How To State A Use Case [2] • ”A use case is most effectively stated from the

perspective of the user as a present-tense verb phrase in active voice, that are precise and clear.”

• ”When it comes to writing text for use cases, expansive is much preferable to terse.”

• [1]: <number> The <something> <some action>

E.g. …. 5. The ReservationMaker provides name, e-mail… 6. The System makes reservation and allocates tag to reservation.

….

Page 25: Use Case Diagrams - Universitetet i Agdergrimstad.uia.no/ikt413/year2012/presentations/pdf/2012-03c-UseCas… · Use Case Diagram - a Part of UML Use case diagrams are often drawn

Use Cases, Jan Pettersen Nytun, slide no. 25

Use Cases As Given in [1] • Use case modeling proceeds as follows:

– find the system boundary – find the actors – find use cases

• The number of use cases can be limited by allowing branching and repetition: – if-statement and if-else-statement – for-loop and while-loop

• (Instead of branching (if the use cases is complex) one can have a primary use case scenario and several secondary scenarios!)

Page 26: Use Case Diagrams - Universitetet i Agdergrimstad.uia.no/ikt413/year2012/presentations/pdf/2012-03c-UseCas… · Use Case Diagram - a Part of UML Use case diagrams are often drawn

Use Cases, Jan Pettersen Nytun, slide no. 26

Use Case: <use case id>

Actors: <actor 1> <actor 2>

Preconditions: 1. <first precondition> 2. ...

Flow of event: 1. <frist step> 2. ...

Postcondition: 1. <first postcondition> 2. ...

Alternative flow: 1. <first step> 2. ...

The actors involved in the use case

The system state before the use case can begin

The sequence of declarative, time-ordered steps in the use case.

The alternative flow can be used to capture branches that can occur at any point in the flow

The system state when the use case is over

Use Cases As Given in [1] continues...

A Use Case Specification

Page 27: Use Case Diagrams - Universitetet i Agdergrimstad.uia.no/ikt413/year2012/presentations/pdf/2012-03c-UseCas… · Use Case Diagram - a Part of UML Use case diagrams are often drawn

Use Cases, Jan Pettersen Nytun, slide no. 27

Example: Make Quiz Logon to system

as QuizMaker User

QuizMaker

«becomes»

Edit quiz repository

Make quiz

Make question

Make answer alternative

Navigate repository

Update question

Update quiz

Update answer alternative

Delete question

Delete quiz

Delete answer alternative

Add predefined question

Add predefined answer alternative

Page 28: Use Case Diagrams - Universitetet i Agdergrimstad.uia.no/ikt413/year2012/presentations/pdf/2012-03c-UseCas… · Use Case Diagram - a Part of UML Use case diagrams are often drawn

Use Cases, Jan Pettersen Nytun, slide no. 28

GUI: View/Edit/Create Quiz

Quiz Name: IKT413 Test

What is UML an abbreviation for?

Browse Selected Questions Question Text

0 Undefined Modeling Language

Browse Selected Answer Alternatives

Correct- ness

Answer Alternative Text

new update

button

delete

new update

add predefined question

editable text field

new update

add predefined answer alternative

Browse Quizzes Quiz

Make Quiz – example continues...

delete

delete

Page 29: Use Case Diagrams - Universitetet i Agdergrimstad.uia.no/ikt413/year2012/presentations/pdf/2012-03c-UseCas… · Use Case Diagram - a Part of UML Use case diagrams are often drawn

Use Cases, Jan Pettersen Nytun, slide no. 29

Correctness

- value : double

Quizzee

QuizResult

- id : String - date : Date

Answer

Quiz

id : String creationDate : Date

0..*

0..*

0..*

Question

- creationDate : Date

0..*

0..*

0..*

0..* 0..*

0..*

0..*

1

0..*

+chosen AnswerAlternative

0..*

1

<<concept>> Simplified PIM for

Quiz-system

Page 30: Use Case Diagrams - Universitetet i Agdergrimstad.uia.no/ikt413/year2012/presentations/pdf/2012-03c-UseCas… · Use Case Diagram - a Part of UML Use case diagrams are often drawn

Use Cases, Jan Pettersen Nytun, slide no. 30

Use Case: Logon to system as QuizMaker Actors: User which becomes QuizMaker

Precondition: 1. User has started the application that lets you define quizzes

Flow of events: 1. while User has not supplied valid <user name> and <password> 1.1. User supplies <user name> and <password> 1.2. if <user name> or <password> not valid then 1.2.1. System gives message <“user name or password incorrect”> 1.3. else 1.3.1. System displays “View/Edit/Create Quiz”-dialog window 1.3.2. System load first quiz in repository to dialog window 1.3.3. System gives ok notification to QuizMaker

Postcondition: 1. The user has been logged onto the system as QuizMaker or the application has exited. Alternative flow: 1. The User can cancel the operation at any time - in which case the application exits.

Make Quiz – example continues...

Page 31: Use Case Diagrams - Universitetet i Agdergrimstad.uia.no/ikt413/year2012/presentations/pdf/2012-03c-UseCas… · Use Case Diagram - a Part of UML Use case diagrams are often drawn

Use Cases, Jan Pettersen Nytun, slide no. 31

Use Case: Navigate repository Actors: QuizMaker

Precondition: 1. System has displayed “View/Edit/Create Quiz”-dialog window

Flow of events: 1. The QuizMaker presses one of the following button: <first quiz>, <next quiz>, <previous quiz> and <last quiz> 2. The system loads the quiz which the QuizMaker navigated to.

Postcondition: Alternative flow: 1. The quiz repository is empty – in which case the <quiz name>-field is left blank.

Make Quiz – example continues...

Page 32: Use Case Diagrams - Universitetet i Agdergrimstad.uia.no/ikt413/year2012/presentations/pdf/2012-03c-UseCas… · Use Case Diagram - a Part of UML Use case diagrams are often drawn

Use Cases, Jan Pettersen Nytun, slide no. 32

Use Case: Make Quiz Actors: QuizMaker

Precondition: QuizMaker has supplied <quiz name> and selected <quiz new>

Flow of events: 1. if <quiz name> already used then 1.1. System gives message <“in use”> to QuizMaker 2. else 2.1 System gives ok notification to QuizMaker

Postcondition: 1. There is a quiz called <quiz name> in the <quiz repository> Alternative flow:

Page 33: Use Case Diagrams - Universitetet i Agdergrimstad.uia.no/ikt413/year2012/presentations/pdf/2012-03c-UseCas… · Use Case Diagram - a Part of UML Use case diagrams are often drawn

Use Cases, Jan Pettersen Nytun, slide no. 33

Use Case Diagrams Contents

- History - The Role of Use Cases - Graphical Notation - Use case scenario - Actor - System Boundary - Use Case Text - One Use Case Approach - Use Case relations - Include - Generalization - Extends - not part of curriculum

Page 34: Use Case Diagrams - Universitetet i Agdergrimstad.uia.no/ikt413/year2012/presentations/pdf/2012-03c-UseCas… · Use Case Diagram - a Part of UML Use case diagrams are often drawn

Use Cases, Jan Pettersen Nytun, slide no. 34

• There are at least three types of relationships: – Include – Generalization – extends – precedes

• Use of these features will typically make a use case diagram more complex to read, so they should be used with caution.

Relationships Between Use Cases

Page 35: Use Case Diagrams - Universitetet i Agdergrimstad.uia.no/ikt413/year2012/presentations/pdf/2012-03c-UseCas… · Use Case Diagram - a Part of UML Use case diagrams are often drawn

Use Cases, Jan Pettersen Nytun, slide no. 35

Stereotypes in UML • Extends and includes is represented with dependency

arrow. The dependency arrow is already used, because of this extends and include must be stereotypes. In UML stereotype names are included in << and >>.

• The following definition can be found in “UML Notation Guide” from Rational Software: “A stereotype is, in effect, a new class of modeling element that is introduced at modeling time. It represents a subclass of an existing modeling element with the same form (attributes and relationships) but with a different intent.”

Page 36: Use Case Diagrams - Universitetet i Agdergrimstad.uia.no/ikt413/year2012/presentations/pdf/2012-03c-UseCas… · Use Case Diagram - a Part of UML Use case diagrams are often drawn

Use Cases, Jan Pettersen Nytun, slide no. 36

Use Case Diagrams Contents

- History - The Role of Use Cases - Graphical Notation - Use case scenario - Actor - System Boundary - Use Case Text - One Use Case Approach - Use Case relations - Include - Generalization

- Extends - not part of curriculum

Page 37: Use Case Diagrams - Universitetet i Agdergrimstad.uia.no/ikt413/year2012/presentations/pdf/2012-03c-UseCas… · Use Case Diagram - a Part of UML Use case diagrams are often drawn

Use Cases, Jan Pettersen Nytun, slide no. 37

• The include relationship indicates that the base use case incorporates the behavior of the other use case.

• The base use case is dependent of the included use case but not the opposite way.

• Functionality shared between two use cases can in this way be extracted out and described in a separate use case.

Include Validate student

Register for course

«include»

base

Page 38: Use Case Diagrams - Universitetet i Agdergrimstad.uia.no/ikt413/year2012/presentations/pdf/2012-03c-UseCas… · Use Case Diagram - a Part of UML Use case diagrams are often drawn

Use Cases, Jan Pettersen Nytun, slide no. 38

Use Case: Student register for course Actors: Student

Precondition: 1. The Student has browsed to the course register page

Flow of events: 1. The Student write <user name> and <password>. 2. include( Validate student ) 3. The System presents all possible courses for this student. 4. The Student select course and commits the entry by pressing the <Enter>- button.

Postcondition: Alternative flow:

Specifying an Inclusion Point

Page 39: Use Case Diagrams - Universitetet i Agdergrimstad.uia.no/ikt413/year2012/presentations/pdf/2012-03c-UseCas… · Use Case Diagram - a Part of UML Use case diagrams are often drawn

Use Cases, Jan Pettersen Nytun, slide no. 39

More On Include • Include is used to define functionality that

is common to several use cases, a modularization technique.

• If we see that a component can be used, we can model this by a separate use case describing the component.

• A scenario that is an instance of the base use case will typically contain a sub scenario from the included one.

Page 40: Use Case Diagrams - Universitetet i Agdergrimstad.uia.no/ikt413/year2012/presentations/pdf/2012-03c-UseCas… · Use Case Diagram - a Part of UML Use case diagrams are often drawn

Use Cases, Jan Pettersen Nytun, slide no. 40

Use Case Diagrams Contents

- History - The Role of Use Cases - Graphical Notation - Use case scenario - Actor - System Boundary - Use Case Text - One Use Case Approach - Use Case relations - Include - Generalization - Extends - not part of curriculum

Page 41: Use Case Diagrams - Universitetet i Agdergrimstad.uia.no/ikt413/year2012/presentations/pdf/2012-03c-UseCas… · Use Case Diagram - a Part of UML Use case diagrams are often drawn

Use Cases, Jan Pettersen Nytun, slide no. 41

• The generalization relationship indicates that the child will inherits the behavior and meaning from the parent use case. The child can alter or/and extend the behavior of the parent, but it should be possible to substitute the child for the parent every place the parent is used.

• Typically much of the use case text of the parent is repeated for the child – and then modified or extended.

Generalization Validate student

Validate student with pin code

parent child

Page 42: Use Case Diagrams - Universitetet i Agdergrimstad.uia.no/ikt413/year2012/presentations/pdf/2012-03c-UseCas… · Use Case Diagram - a Part of UML Use case diagrams are often drawn

Use Cases, Jan Pettersen Nytun, slide no. 42

Use Case Diagrams Contents

- History - The Role of Use Cases - Graphical Notation - Use case scenario - Actor - System Boundary - Use Case Text - One Use Case Approach - Use Case relations - Include - Generalization - Extends - not part of curriculum

Page 43: Use Case Diagrams - Universitetet i Agdergrimstad.uia.no/ikt413/year2012/presentations/pdf/2012-03c-UseCas… · Use Case Diagram - a Part of UML Use case diagrams are often drawn

Use Cases, Jan Pettersen Nytun, slide no. 43

• If a use case incorporates two or more clearly different scenarios (i.e., the two scenarios are quite similar except for a section that is different) – and some condition dictates which - this can be modeled by an extend relation.

• So the extend relationship can be used to model behavior that the user sees as optional or as an exception on normal behavior. The base use case can incorporate the extended behavior under certain conditions otherwise stand alone.

Extend

Page 44: Use Case Diagrams - Universitetet i Agdergrimstad.uia.no/ikt413/year2012/presentations/pdf/2012-03c-UseCas… · Use Case Diagram - a Part of UML Use case diagrams are often drawn

Use Cases, Jan Pettersen Nytun, slide no. 44

You should specify: – The condition under which the extended use case applies – At which point the condition is tested and the behavior

may diverge; this point is called the extension point.

Extend - The Notation

Issue Diploma Extension points

<exams not completed>

Issue Incomplete Diploma

«extend»

base

Condition: {exams not complete} Extension point: exams not completed

exception

Page 45: Use Case Diagrams - Universitetet i Agdergrimstad.uia.no/ikt413/year2012/presentations/pdf/2012-03c-UseCas… · Use Case Diagram - a Part of UML Use case diagrams are often drawn

Use Cases, Jan Pettersen Nytun, slide no. 45

Use Case: Issue Diploma

Actors: Admin

Precondition:

Flow of events: 1. Admin enter student name. 2. <exams not completed> The system produces a diploma

Postcondition: Alternative flow:

Specifying an Extension Point Use Case:

Issue Incomplete Diploma Actors: Admin

Precondition: 1. The student has been selected 2. Some exams are missing Flow of events:

1. The system produces an incomplete diploma

Postcondition: Alternative flow:

Page 46: Use Case Diagrams - Universitetet i Agdergrimstad.uia.no/ikt413/year2012/presentations/pdf/2012-03c-UseCas… · Use Case Diagram - a Part of UML Use case diagrams are often drawn

Use Cases, Jan Pettersen Nytun, slide no. 46

Use Case from Booch et al.

Place order Extension points

set priority

Place rush order

Validate user

Track order

Check password

«include»

«include»

«extend»

Condition: {rush order} Extension point: set priority

Page 47: Use Case Diagrams - Universitetet i Agdergrimstad.uia.no/ikt413/year2012/presentations/pdf/2012-03c-UseCas… · Use Case Diagram - a Part of UML Use case diagrams are often drawn

Use Cases, Jan Pettersen Nytun, slide no. 47

UML 2.0 Extend This relationship specifies that the behavior of a use case may be

augmented by an additional use case. The extension takes place at one or more specific extension points defined in the extended use case. Note, however, that the extended use case is defined independently of the extending use case. Use case extension is intended to be used when there is some additional behavior that should be added, conditionally, to the behavior defined in another use case (which is meaningful independently of the extending use case)....

Semantics

If the condition of the extension is true at the time the first extension point is reached during the execution of the extended use case, then all of the appropriate behavior fragments of the extending use case will also be executed. If the condition is false, the extension does not occur. The individual fragments are executed as the corresponding extension points of the extending use case are reached. Once a given fragment is completed, execution continues with the behavior of the extended use case following the extension point. Note that even though there are multiple use cases involved, there is just a single behavior execution.

Page 48: Use Case Diagrams - Universitetet i Agdergrimstad.uia.no/ikt413/year2012/presentations/pdf/2012-03c-UseCas… · Use Case Diagram - a Part of UML Use case diagrams are often drawn

Use Cases, Jan Pettersen Nytun, slide no. 48

• This relations are very similar, some claim that UML would be better off with only one of them!

• How to select one of them: – Extend: If you wants to describe extra behavior

that is to be used under certain condition; a condition that is tested at run time.

– Generalization: If you have a specialization of a whole use case.

Extend and Generalization

Page 49: Use Case Diagrams - Universitetet i Agdergrimstad.uia.no/ikt413/year2012/presentations/pdf/2012-03c-UseCas… · Use Case Diagram - a Part of UML Use case diagrams are often drawn

Use Cases, Jan Pettersen Nytun, slide no. 49

Another relationship between use cases

• [2]”You use precedes to indicate that one use case precedes another within a logical sequence.”

Buyer

logon Issue Diploma «precedes»

Page 50: Use Case Diagrams - Universitetet i Agdergrimstad.uia.no/ikt413/year2012/presentations/pdf/2012-03c-UseCas… · Use Case Diagram - a Part of UML Use case diagrams are often drawn

Use Cases, Jan Pettersen Nytun, slide no. 50

References [1] Jim Arlow and Ila Neustadt: UML and The Unified Process, 2002, Addison-Wesley [2] Doug Rosenberg and Kendall Scott: Use Case Driven Object Modeling with UML:

A Practical Approach, Addison-Wesley

- Ivar Jacobson: Object-Oriented Software Engineering: A Use Case Driven Approach. Addison-Wesley, 1994

- Martin Fowler with Kendall Scott: UML Distilled. Addison-Wesley, 1997

- Grady Booch, James Rumbaugh, Ivar Jacobson: The Unified Modeling Language User Guide.Addison-Wesley, 1999

- Terry Quatrani: Visual Modeling with Rational Rose and UML. Addison-Wesley, 1998

- Daniel Tkach, Walter Fang and Andrew So: Visual Modeling Technique, 1996 - Alistair Cockburn’s Web: http://members.aol.com/acockburn - Rational software: http://www.rational.com/uml/documentation.html - Alistair Cockburn: http://members.aol.com/acockburn