49
Using UML, Patterns, and Java Object-Oriented Software Engineering Functional Modeling

Functional Modeling Oriented Software Engineering Using UML, Patterns, and Javadumoulin/enseign/2013-2014/coa/cours/06... ·  · 2014-09-08Bernd Bruegge & Allen H. Dutoit Object-Oriented

Embed Size (px)

Citation preview

Usi

ng U

ML,

Pat

tern

s, a

nd J

ava

Obj

ect-O

rient

ed S

oftw

are

Engi

neer

ing

Functional Modeling

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 2

Outline

Scenarios (Lecture Requirements Elicitation)Finding ScenariosIdentifying actors

Use Cases• Finding Use Cases• Flow of Events• Use Case Associations • Use Case Refinement

• Summary

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 3

Scenario example : Warehouse on Fire

• Bob, driving down main street in his patrol car notices smoke coming out of a warehouse. His partner, Alice, reports the emergency from her car.

• Alice enters the address of the building into her wearable computer , a brief description of its location (i.e., north west corner), and an emergency level.

• She confirms her input and waits for an acknowledgment.• John, the dispatcher, is alerted to the emergency by a

beep of his workstation. He reviews the information submitted by Alice and acknowledges the report. He allocates a fire unit and sends the estimated arrival time (ETA) to Alice.

• Alice received the acknowledgment and the ETA.

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 4

Observations about Warehouse on Fire Scenario• Concrete scenario

• Describes a single instance of reporting a fire incident.

• Does not describe all possible situations in which a fire can be reported.

• Participating actors• Bob, Alice and John

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 5

Other Scenarios Possibilities for an Incident Management System• What needs to be done to report a “Cat in a

Tree” incident?• Who is involved in reporting the incident?• What does the system do, if no police cars are

available? If the police car has an accident on the way to the “Cat in a Tree” incident?

• What do you need to do if the “Cat in the Tree” turns into a “Grandma Has Fallen From the Ladder”?

• Can the system cope with simultaneous incident reports “Cat in the Tree” and “Warehouse on Fire?”

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 6

After the scenarios are formulated• Find all the use cases in the scenario that

specify all instances of how to report a fire and model them in a use case model

• Example: “Report Emergency“ in the first paragraph of the scenario is a candidate for a use case

• Then add more detail to each of these use cases by describing: 1.Name of the use case2.Participating actors3.Describe the entry condition 4.Describe the flow of events 5.Describe the exit condition 6.Describe exceptions7.Describe quality requirements (nonfunctional

requirements).

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 7

ReportEmergency

Use Case Modeling

• A use case is a flow of events in the system, including interaction with actors

• Each use case has a name• Each use case has a termination condition• Graphical notation: An oval with the name of the use case

Use Case Model: The set of all use cases specifying the complete functionality of the system

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 8

Use Case Model for Incident Management

ReportEmergency

FieldOfficer Dispatcher OpenIncident

AllocateResources

<<initiates>><<initiates>>

<<initiates>>

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 9

How to find Use Cases

• Select a narrow vertical slice of the system (i.e. one scenario)

• Discuss it in detail with the user to understand the user’s preferred style of interaction

• Select a horizontal slice (i.e. many scenarios) to define the scope of the system.

• Discuss the scope with the user• Use illustrative prototypes (mock-ups) as visual

support• Find out what the user does

• Task observation (Good)• Questionnaires (Bad)

Use Case Example: ReportEmergency1. Use case name: ReportEmergency2. Participating Actors:

Field Officer, Dispatcher

3. Entry Condition:The FieldOfficer is logged into the FRIEND System

4. Flow of Events: on next slide5. Exit Condition:

The FieldOfficer has received an acknowledgement and the selected response OR The FieldOfficer has received an explanation indicating why the transaction could not be processed

6. Exceptions:• The FieldOfficer is notified immediately if the connection

between terminal and central is lost 7. Quality Requirements:

• The FieldOfficer’s report is acknowledged within 30 seconds.

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 11

Use Case Example: ReportEmergency (ctd)

4. Flow of Events (~ scenario d’analyse, ou abstrait ):1. The FieldOfficer activates the “Report Emergency” function

of her terminal. The system responds by presenting a form to the officer.

2. The FieldOfficer fills the form, by selecting the emergency level, type, location, and brief description of the situation. The FieldOfficer also describes a response to the emergency situation. Once the form is completed, the FieldOfficer submits the form, and the Dispatcher is notified.

3. The Dispatcher creates an Incident in the database by invoking the OpenIncident use case. He selects a response and acknowledges the report.

4. The FieldOfficer receives the acknowledgment and the selected response.

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 12

Another Example: Allocate a Resource

• Glossary Entries:• Field Supervisor: This is the official at the

emergency site• Resource Allocator: The Resource Allocator is

responsible for the commitment and release of Resources managed by the FRIEND system

• Dispatcher: A Dispatcher enters, updates, and removes Emergency Incidents, Actions, and Requests in the system. The Dispatcher also closes Emergency Incidents

• Field Officer: Reports accidents from the Field

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 13

Allocate a Resource (cont’d)

1. Use case name: AllocateResources2. Participating Actors:

Field Officer, Dispatcher, Resource Allocator, Field Supervisor3. Entry Condition:

The Resource Allocator has selected an available resource4. Flow of Events:

1. The Resource Allocator selects an Emergency Incident2. The Resource is committed to the Emergency Incident

5. Exit Condition:The use case terminates when the resource is committedThe selected Resource is unavailable to other Requests.

6. Special Requirements:The Field Supervisor is responsible for managing Resources.

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 14

Order of steps when formulating use cases

• First step: Name the use case• Use case name: ReportEmergency

• Second step: Find the actors• Generalize the concrete names from the scenario to

participating actors• Participating Actors:

• Field Officer (Bob and Alice in the Scenario)• Dispatcher (John in the Scenario)

• Third step: Concentrate on the flow of events• Use informal natural language

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 15

Another Use Case Example

Flow of Events• The Bank Customer specifies a Account and

provides credentials to the Bank proving that he is authorized to access the Bank Account

• The Bank Customer specifies the amount of money he wishes to withdraw

• The Bank checks if the amount is consistent with the rules of the Bank and the state of the Bank Customer’s account. If that is the case, the Bank Customer receives the money in cash.

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 16

Use Case Attributes

Use Case Name Withdraw Money Using ATM

Participating Actor: Bank Customer

Entry condition:• Bank Customer has opened a Bank Account with

the Bank andBank Customer has received an ATM Card and PIN

Exit condition:• Bank Customer has the requested cash or

Bank Customer receives an explanation from the ATM about why the cash could not be dispensed.

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 17

7. The Bank Customer inputs an amount

3. The Bank Customer types in PIN

5. The Bank Customer selects an account

Flow of Events: A Request-Response Interaction between Actor and System

1.The Bank Customer inserts the card into the ATM

8.The ATM outputs the money and a receipt and stops the interaction.

4. If several accounts are recorded on the card, the ATM offers a choice of the account numbers for selection by the Bank Customer

6.If only one account is recorded on the card or after the selection, the ATM requests the amount to be withdrawn

System steps

2.The ATM requests the input of a four-digit PIN

Actor steps

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 18

Use Case Exceptions

Actor steps1.The Bank Customer inputs

her card into the ATM.[Invalid card]

3.The Bank Customer types in PIN. [Invalid PIN]

5. The Bank Customer selects an account .

7. The Bank Customer inputs an amount. [Amount over limit]

[Invalid card]The ATM outputs the card and stops the interaction.

[Invalid PIN]The ATM announces the failure and offers a 2nd try as well as canceling the whole use case. After 3 failures, it announces the possible retention of the card. After the 4th failure it keeps the card and stops the interaction.

[Amount over limit]The ATM announces the failure and the available limit and offers a second try as well as canceling the whole use case.

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 19

CONSEILS POUR FORMULER LES SCÉNARIOS

(hors livre)

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 20

Description textuelle d’un Cas d’Utilisation

• Comprend• un nom pour le CU• une description brève du CU• un context (transparent suivant)• La liste des scénarios

• un scénario nominal, représentant le flot « normal »• Plusieurs scénarios alternatifs

• Des besoins additionnels• performances, fiabilités, …

• Le scénario nominal• celui où tout se passe bien

• Le corps des scénarios• ensemble d’actions (ou étapes) séquentielles ou pas.

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 21

Contexte d'un cas d’utilisation

• Conditions d’utilisation: pré-condition• Le client a un compte• L’utilisateur a choisi l’article sur lequel il veut enchérir

• Le déclenchement (acteur(s) et sur quelle action)• Le client insère sa carte de crédit,• L’utilisateur fait une offre

• Les garanties à respecter• en cas d’échec (l’objectif ne peut pas être atteint)

• liste des « promesses » par exemple: • Retour à l’état d’avant le déclenchement• Création d’un journal des incidents

• en cas de succès• Ces garanties doivent satisfaire tous les intervenants• Correspond généralement à la post condition (le résultat observable)

• {La somme débitée sur le compte client= somme délivrée au distributeur}

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 22

Comment nommer un Cas d’Utilisation

• Le nom est choisi à partir du point de vue de l’acteur

• Le nom doit être parlant pour l’utilisateur (et pas nécessairement pour le développeur du système)

• Verbe + complément

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 23

Liste des scénarios

• Un Cas d’utilisation regroupe des scénarios:• scénarios de succès:

• Tous les intérêts (des intervenants) sont satisfaits• scénarios d’échec:

• Tous les intérêts (des intervenants) doivent être protégés

• Les principaux écueils des cas d’utilisation sont :

• Leur apparence fonctionnelle• il ne faut pas réinventer l’approche fonctionnelle et rester

dans une démarche objet. • Un trop grand nombre de C.U. est le symptôme d’une

dérive fonctionnelle.• Le degré de description (granularité): en particulier

la distinction entre cas d’utilisation et scénario.

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 24

Contenu des étapes d’un scénario

• Un scénario contient 3 sortes d ’étapes :

• La première étape du scénario n’obéit pas à cette classification

• Elle indique généralement l’événement qui déclenche le scénario

• Le client insère sa carte de crédit,• L’utilisateur fait une offre

Le Système enregistre la transaction et met à jour le solde du compte client

Les changements internes

Le Système vérifie la validité du nom et du compteLes validations

Le Système affiche le nom et l'adresse du patientLes interactions (in, out)

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 25

Description d’un scénarioExemple

• Scénario principale (succès)1.Le client arrive à la caisse avec des articles2.Le caissier commence une nouvelle vente3.Le caissier entre le code de l’article4.…

• Le caissier répète les étapes 3 et 4 jusque épuisement des articles

5.…

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 26

Description d’un scénario abstrait Conseils• Pour chaque description d’action, utiliser une phrase

courte de la forme:• Sujet + verbe + complément d’objet direct + autre

complément.• Le système + vérifie + la validité + du nom

• Toujours préciser qui fait l’action :• l’acteur, le système, un sous système,…

• Ne pas privilégier une vue plutôt qu’une autre (côté acteur, côté système)

• Ne pas écrire • prendre la carte du client, mettre la carte de crédit dans le

distributeur• mais préférez:

• le client introduit la carte dans le distributeur

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 27

Description d’un scénario abstrait Conseils (suite)

• Privilégier les intention pas les gestes:1. Le systèmes demande les coordonnées de l’utilisateur2. L’utilisateur saisit ses cordonnées3. L’utilisateur clique sur OK

• 2&3 sont inutiles

• Le nombre d’étapes doit être raisonnable • entre 3 et 10• nécessité de grouper/décomposer

• Validation ou vérification?• Vérification => si mot de passe OK alors ????• Validation => le système valide que le mot de passe est correct

(pas de si)

• Numéroter ou pas les actions?• uniquement si nécessaire

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 28

Scénarios alternatifs

• Principe: • A partir du scénario nominal, à chaque point où une

condition est sous entendue, écrire clairement la condition et la prise en charge de cette condition, c’est à dire décrire une suite d’étapes qui se termine soit par la satisfaction soit par l’abandon de l’objectif.

• On distingue • les vrais scénarios alternatifs qui conduisent à la post

condition • et les scénarii-exception qui entraînent l'abandon du

CU

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 29

Scénarios alternatifsExemple

• Dans le scénario nominal: • L’utilisateur saisit son mot de passe• le système valide que le mot de passe est correct

• Alternatives:• [Le mot de passe entré est incorrect]: le système

redemande le mot de passe,……

• Exception• [le délai pour entrer le mot de passe est dépassé]:

suite d’étapes conduisant à l’abandon de l’objectif

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 30

Scénarios alternatifsRemarques: • A chaque fois que le système valide

=> une alternative/exception• [code entré incorrect]:• [solde insuffisant]:

• A chaque comportement anormal de l’utilisateur => une alternative/exception

• [délai expiré]:

• A chaque possibilité de panne interne du système => une alternative/exception

• [Plus assez de billets dans le distributeur]:• [panne réseau]:

• …..

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 31

Numérotation des étapes

• Un scénario alternatif, peut conduire• à un échec• mais également au retour au scénario nominal, • on va alors utiliser les numéros d’étape pour ne pas tout réécrire,

• exemple :• Scénario nominal:

• 2. ….• 3. L’utilisateur saisit le mot de passe• 4. Le système valide le mot de passe• 5. ….

• Scénario alternatif:• 4a. [mot de passe incorrect]:

• Le système signale l’erreur et redemande le mot de passe• L’utilisateur saisit le mot de passe

• Scénario-Exception• 4b.[nombre de saisies incorrectes trop grand]:

• Le système prévient l’utilisateur• Le système «met fin à la session »

• Attention: à garder lisible les scénarios. (alternative dans une alternative dans …..)

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 34

CONSEILS POUR FORMULER LES SCÉNARIOS

D’après le livre

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 35

Guidelines for Formulation of Use Cases (1)

• Name• Use a verb phrase to name the use case• The name should indicate what the user is trying to

accomplish• Examples:

• “Request Meeting”, “Schedule Meeting”, “Propose Alternate Date”

• Counter Examples• “Add Participants”, “Add Date To Exclusion Set”

• Length• A use case description should not exceed 1-2 pages. If

longer, use include relationships• A use case should describe a complete set of

interactions.

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 36

Guidelines for Formulation of Use Cases (2)

Flow of events:• Use the active voice. Steps should start either

with “The Actor” or “The System …”• The causal relationship between the steps

should be clear• All flow of events should be described (not only

the main flow of event)• The boundaries of the system should be clear.

Components external to the system should be described as such

• Define important terms in the glossary.

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 37

7. The Bank Customer inputs an amount

3. The Bank Customer types in PIN

5. The Bank Customer selects an account

Event Flow: Use Indentation to show the Interaction between Actor and System1.The Bank Customer inserts the card into the ATM

8.The ATM outputs the money and a receipt and stops the interaction.

4. If several accounts are recorded on the card, the ATM offers a choice of the account numbers for selection by the Bank Customer

6.If only one account is recorded on the card or after the selection, the ATM requests the amount to be withdrawn

2.The ATM requests the input of a four-digit PIN

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 38

Example of a badly written Use Case

“The driver arrives at the parking gate, the driver receives a ticket from the distributor, the gate is opened, the driver drives through.”

What is wrong with this use case?

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 39

Example of a badly written Use Case

“The driver arrives at the parking gate, the driver receives a ticket from the distributor, the gate is opened, the driver drives through.”

• It has no actors• It is not clear which action triggers the ticket being issued• Because of the passive form, it is not clear who opens the gate

• The driver? The computer? A gate keeper?• It is not a complete transaction

• A complete transaction would also describe the driver paying for the parking and driving out of the parking lot.

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 40

How to write a use case (Summary)• Name of Use Case• Actors

• Description of Actors involved in use case• Entry condition

• “This use case starts when…”• Flow of Events

• Free form, informal natural language• Exit condition

• “This use cases terminates when…”• Exceptions

• Describe what happens if things go wrong• Quality Requirements

• Nonfunctional Requirements, Constraints

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 41

Use Case Associations

• Dependencies between use cases are represented with use case associations

• Associations are used to reduce complexity• Decompose a long use case into shorter ones• Separate alternate flows of events• Refine abstract use cases

• Types of use case associations• Includes• Extends• Generalization

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 42

<<include>>: Functional Decomposition• Problem:

• A function in the original problem statement is too complex

• Solution: • Describe the function as the aggregation of a set of

simpler functions. The associated use case is decomposed into shorter use cases

ManageIncident

CreateIncident HandleIncident CloseIncident

<<include>>

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 43

<<include>>: Reuse of Existing Functionality• Problem: There are overlaps among use cases.

How can we reuse flows of events instead of duplicating them?

• Solution: The includes association from use case A to use case B indicates that an instance of use case A performs all the behavior described in use case B (“A delegates to B”)

• Example: Use case “ViewMap” describes behavior that can be used by use case “OpenIncident” (“ViewMap” is factored out)

ViewMapOpenIncident

AllocateResources

<<include>>

<<include>>

Base UseCase

SupplierUse Case

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 44

<<extend>> Association for Use Cases• Problem: The functionality in the original

problem statement needs to be extended.• Solution: An extend association from use case A

to use case B• Example: “ReportEmergency” is complete by

itself, but can be extended by use case “Help” for a scenario in which the user requires help

ReportEmergency

FieldOfficerHelp

<<extend>>

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 45

Generalization in Use Cases• Problem: We want to factor out common (but not

identical) behavior. • Solution: The child use cases inherit the behavior

and meaning of the parent use case and add or override some behavior.

• Example: “ValidateUser” is responsible for verifying the identity of the user. The customer might require two realizations: “CheckPassword” and “CheckFingerprint”

ValidateUserParentCase

ChildUse Case

CheckPassword

CheckFingerprint

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 46

Summary

• Scenarios:• Great way to establish communication with client• Different types of scenarios: As-is scenario, visionary

scenario, evaluation scenario and training scenario• Use cases

• Abstractions of scenarios• Use cases bridge the transition between

functional requirements and objects.

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 47

Que faire ensuite ?

• Lire les lectures obligatoire et conseillée• Obligatoire : Bruegge&Dutoit, Object-Oriented

Software Engineering- Chap 5 - 5.1, 5.2, 5.3, 5.4, 5.5.1

• Conseillée : Chapter 1 Bruegge&Dutoit

• Visiter le portail de COA

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 48

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 49

Additional Slides

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 50

Example: Accident Management System

• What needs to be done to report a “Cat in a Tree” incident?

• What do you need to do if a person reports “Warehouse on Fire?”

• Who is involved in reporting an incident?• What does the system do, if no police cars are

available? If the police car has an accident on the way to the “Cat in a Tree” incident?

• What do you need to do if the “Cat in the Tree” turns into a “Grandma Has Fallen From the Ladder”?

• Can the system cope with a simultaneous incident report “Warehouse on Fire?”

Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java 51

ReportEmergency

Use Case Modeling

• A use case is a flow of events in the system, including interaction with actors

• Each use case has a name• Each use case has a termination condition• Graphical notation: An oval with the name of the use case

Use Case Model: The set of all use cases specifying the complete functionality of the system