introduction to uml, the unified modeling language

187
© 2004 Jean-Paul Rigault 27/10/22 11:44 1 Introduction to UML, the Unified Modeling Language Jean-Paul Rigault School of Computing (ESSI) University of Nice Sophia Antipolis Email: [email protected]

Upload: hannelore-evan

Post on 31-Dec-2015

75 views

Category:

Documents


7 download

DESCRIPTION

Introduction to UML, the Unified Modeling Language. Jean-Paul Rigault School of Computing (ESSI) University of Nice Sophia Antipolis Email: [email protected]. Outline. Introduction: modeling and OO modeling Application modeling with Use Cases Class and object modeling State modeling. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 1

Introduction to UML, the

Unified Modeling Language

Jean-Paul RigaultSchool of Computing (ESSI)

University of Nice Sophia AntipolisEmail: [email protected]

Page 2: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 2

Outline

Introduction: modeling and OO modeling

Application modeling with Use Cases Class and object modeling State modeling

Page 3: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 3

Introduction to UML

Introduction: Modeling and Object-Oriented

Modeling

Page 4: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 4

Introduction

What is modeling? What is object-oriented modeling? What is UML? Technical activities in OO modeling

Page 5: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 5

What is Modeling?

Modeling is customary in engineering disciplines

A model is a simplification of reality

Handling the real world complexity

The four aims of modelling

Visualize the system Specify its structure and

behavior Provide a template to help us

build the system Document decisions made

Examples of models Textual description Catalogue, Data book… Blueprint Scale model Formal descriptions

Equations Finite state machines Set theoretic

descriptions… etc.

Page 6: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 6

What is Modeling? Principles of Modeling

The choice of a way of modelling influences

how a problem is tackled how a solution is

elaborated No single model is

sufficient Different levels of

abstraction (refinement) Different points of view

Example: models of a house

Different levels of refinement 3D view rough floor plan floor plan with room

dimensions Different points of view

architect ’s view mason ’s view plumber ’s view electrician ’s view

Page 7: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 7

What is Object-Oriented Modeling?Technical activities in OO modeling

Business modeling

Object modeling

Analysis and Design

Code andunit testing

Application modeling(Product definition

Requirement Analysis)Integration, validation,

maintenance,management,

etc.

Domainanalysis

Page 8: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 8

What is Object-Oriented Modeling?

Vehicle

CarVan

AircraftBoat

Basic Concepts

Abstraction

TestVerifValid

Exec Simulation

Real World

Vehicle

Plane Boat Car

Abstraction

Model

RealizationCode

Domainanalysis Modeling

Page 9: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 9

Overview of UMLA Brief History

Many OOAD methods(> 50)

Coad-Yourdon

Shlaer-Mellor

Fusion

etc.

1991 1992 1993 1994 1995 1996 1997 1998 … 2004

Booch (Rose)Good for design

and construction

Rumbaugh (OMT)Good for analysis and

data-intensive systems

Jacobson (OOSE)Good for the capture

of requirements

UML

0.8UML

0.9

Rational

UML

1.0

UML

1.1

OMG request

UMLconsortium

UML

1.2

UML

1.3

UML

2.0

OMG

OMG vote

Page 10: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 10

Overview of UMLWhat is UML and what is it for?

UML is a language for Visualizing Specifying Constructing Documenting

the artifacts of a software-intensive system

Syntax, Semantics (verification)

Graphics

Architecture and behaviorAllow code generation

Textual and graphic descriptions

Page 11: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 11

Overview of UMLWhat is UML and what is it for?

Software intensive systems… Enterprise information systems; Banking and financial services Telecommunications Transportation; Defense; Aerospace Medical electronics Scientific applications Distributed Web-based services etc.

But also non-software systems Workflow Patient healthcare systems Hardware design…

Page 12: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 12

Overview of UMLWhat is a UML Model?

A Use Case view Functional

requirements Several object

views Different concerns

(architecture, behaviour…)

Different levels of description (analysis, design, implementation…)

StateDiagramsUse Case

DiagramsUse CaseDiagramsUse CaseDiagrams

ScenarioDiagramsScenarioDiagramsCollaborationDiagrams

StateDiagramsStateDiagramsComponentDiagrams

ComponentDiagramsComponentDiagramsDeployment

Diagrams

StateDiagramsStateDiagramsObjectDiagrams

ScenarioDiagramsScenarioDiagramsStatechartDiagrams

Use CaseDiagramsUse CaseDiagramsSequenceDiagrams

StateDiagramsClassDiagrams

ActivityDiagrams

ModelElements

Page 13: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 13

Overview of UMLUML and Software Methodologies

The UML is methodology independent However it is better suited to a

development process that is Use case driven Architecture centric Iterative and incremental

Page 14: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 14

Technical activities in OO modelingUML Views for Technical Activities

Business modelingUSE CASES, ACTIVITYCLASSES

Object modelingCLASSESSEQUENCESSTATES

Analysis and DesignCLASSES SEQUENCES STATES

Code andunit testing

Application modeling

USE CASES, ACTIVITYIntegration, validation,

maintenance,management,

etc.

Page 15: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 15

Introduction to UML

Application Modeling (Product Definition/Requirement

Analysis)with Use Cases

Page 16: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 16

Modeling Requirements in UML

Functional requirements Modeled as Use Cases

Non-functional requirements Some are specific to one use case Some relate to technical issues addressed by

implementation diagrams and models Other in some supplementary documents, out of

the UML scope…

Page 17: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 17

The Use Case ApproachWhat is a Use Case?

Set of sequences of actions that a system performs and that yields an observable result

A set of related services provided by the system, together with scenarios of use

Examples Place an order, Subscribe to a service Land an aircraft, Pilot a car…

Page 18: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 18

The Use Case ApproachWhat is an Actor? (1)

Actors are anything which interface with the system People, other systems, hardware, software, networks…

They are roles, not necessarily full-fledged objects Actors are usually named by nouns corresponding to roles

Actors participate or are interested in the result of Use Cases

Actors are not part of the system They are just at the boundary; They won’t produce code!

Page 19: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 19

The Use Case ApproachWhat is an Actor? (2)

Several sorts of Actors Humans, systems…; Primary and secondary

Primary actor Triggers actions in the system At least one per use case

Secondary actors Support the activity, do not initiate it

Stakeholders Interested in the actions, but not necessarily

participating

Page 20: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 20

The Use Case ApproachA Simplified ATM (1)

The ATM is associated with only one bank

It gives access to all the accounts the customer owns in the bank

Several types of transactions can be chained in a single session

Withdrawal, deposit, transfer between the customer’s own accounts, consulting an account

The customer may obtain a printed receipt for each transaction

Page 21: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 21

The Use Case ApproachA Simplified ATM (2)

The card contains an ID number an expiration date a secret code

The card must be verified by the ATM

The customer cannot make more than 3 attempts to enter the correct code, otherwise the card is swallowed

Interface Keyboard and screen, with menus The customer may cancel the current

transaction at meaningful points

Page 22: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 22

The Use Case ApproachA Simplified ATM (3)

Minimal connection with the bank When a session is opened, a connection

makes it possible to known all the accounts the customer owns

Every night, the information about the current day transactions are transferred to the bank

Manual interventions: an employee

empties the machine and/or fills it with bank notes

supplies consumables and does any maintenance that may be needed

Page 23: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 23

The Use Case ApproachModeling Use Cases

Informal descriptions (non UML) Describing scenarios Just prose

More formal description (UML models) Use Case diagrams Activity diagrams (Sequence and Collaboration diagrams)

Page 24: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 24

Informal UC DescriptionActors

Identifying actors Who uses, installs, starts

up, shuts down, maintains the system?

Who provides (gets) information to (from) the system?

What other systems use the system?

Who has non-functional needs with respect to the system?

ATM example Customer Bank (computer

system) Technician

What about the card?

Page 25: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 25

Informal UC DescriptionTop Level Use Cases

A full set of related system functionalities

Identifying use cases Actors expectations Creating, consulting,

updating or deleting system information?

Notification of an actor state change or of an external event

Start to end a complete use of the

system

ATM example Handle Session: Run a

customer complete session from start (card insertion) to end (card retrievial or swallowing)

Transfer Daily: Nightly retrieval of information by the Bank computer system

Maintain: Run a maintenance session

Page 26: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 26

Informal UC DescriptionUse Cases and Scenarios (1)

Use cases classify the ways of using the system

To each use case correspond many possible usage scenarios A scenario is a sequence of interaction between the

system and one or several actors It expresses a particular path to traverse its use case

Thus scenarios are instances of use cases specify use cases

Page 27: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 27

Informal UC DescriptionUse Cases and Scenarios (2)

Each use case has generally a primary scenario: typical usage several secondary (more exceptional) scenarios

A scenario involves one or several actors Usually one primary actor, and possibly supporting ones

It may have an initiator actor (often, the primary one) A scenario may be of interest to stakeholders, which are

not always participating actors Example: regulation policy, board of directors, share

owners…

Page 28: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 28

Informal UC DescriptionAlistair Cockburn’s Style (1)

Describe a full Use Case with a primary (typical) scenario and possible variants

Involve a primary actor, a possible initiator actor (may be

the primary) and possible supporting actors the interest of some stakeholders

Several possible patterns Brief (a simple sentence/paragraph) Informal text, yet obeying simple writing rules… Highly structured text (fully-dressed)

Page 29: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 29

Informal UC DescriptionA. Cockburn’s Style: Brief

Handle Session Use CaseThe Customer inserts the card into the ATM. After verification and authentication, the customer may perform one or several transactions. When done, the customer gets the card back and leaves.

Page 30: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 30

Informal UC DescriptionA. Cockburn’s Style: Informal

Use Case: Handle SessionPrimary actor (and initiator): CustomerSupporting actor: Bank

The customer inserts the card into the ATM. The ATM verifies the card and authenticates the customer. The ATM retrieves customer information from the Bank. The customer selects a transaction among withdrawal, deposit, transfer, and consult. After completion of the transaction, the Customer may decide to select an other transaction or to quit (in which case, he/she gets the card back).

If the card is invalid or the customer fails to authenticate, the card is swallowed.

Page 31: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 31

Informal UC DescriptionA. Cockburn’s Style: Fully-dressed (1)

For each use case Actors and stakeholders: as for informal Pre- and post-conditions

Pre-condition:: must be true before starting (intiating) the UC

Post-condition: guaranteed to be true after UC completion

One primary scenario (composed of 2-8/10 steps) Several variants associated with the (primary)

scenario steps Other information: Exceptions and errors (specific

variants), Data needed, Constraints…

Page 32: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 32

Informal UC DescriptionA. Cockburn’s Style: Fully-dressed (2)

Primary scenario steps and variants are numbered 1,2,3… in primary 2a for first variant, expressed in informal style, of step 2 2b1,2b2,2b3… for variant b , expressed in fully-dressed,

form, of step 2 For each step

Express a functionality in a simple sentence The subject of the sentence is one of the actors or the

system Use positive verbs in active form

Page 33: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 33

Informal UC DescriptionA. Cockburn’s Style: Fully-dressed (3)

Use Case: Handle SessionPrimary actor (initiator): CustomerSupporting actor: BankPrecondition: ATM is freePrimary Scenario1. Customer inserts the card into

ATM.2. ATM asserts card validity.3. Customer authenticates with ATM.4. ATM gets Customer information

from Bank.5. Customer performs a transaction.6. Customer quits.7. ATM ejects card , Customer takes itPostcondition: ATM is free and all

transactions have been recorded

Page 34: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 34

Informal UC DescriptionA. Cockburn’s Style: Fully-dressed (4)

Use Case: Handle SessionPrimary actor (initiator): CustomerSupporting actor: BankPrecondition: ATM is freePrimary Scenario1. Customer inserts the card into

ATM.2. ATM asserts card validity.3. Customer authenticates with ATM.4. ATM gets Customer information

from Bank.5. Customer performs a transaction.6. Customer quits.7. ATM ejects card , Customer takes itPostcondition: ATM is free and all

transactions have been recorded

Variants2a Card is invalid: ATM swallows it; this

ends the session.3a Customer fails to authenticate: ATM

swallows card; this ends the session.4a The connection with Bank is

impossible or interrupted: ATM ejects the card; this ends the session.

5a Customer quits immediately.6a Customer chooses to perform

another transaction: go to step 5.7a Customer does not get card back

quickly enough: ATM beeps

* Customer may cancel session: ATM ejects the card.

Page 35: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 35

Informal UC DescriptionBest Practices

Give a meaningful name to each use case

Usually an active verbal form The name should correspond

to the objective of the expected (business) service

Do not model outside the system!

Bad Customer use cases choosing a particular ATM

machine deciding how much

money to withdraw

Do not model at too low level!

Bad Customer top level use cases

insert the card enter secret code, get

ticket select transaction type,

select accounts, select amount…

Even worse push the Enter button

on the keyboard…

Page 36: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 36

Formal UC DescriptionTop Level UC Diagram

Handle Session

Transfer Daily

Maintain

Bank

Technician

Customer

association

initiator

supporting

systemlimit

Page 37: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 37

Formal UC DescriptionUC Decomposition (1)

The realization of each top level use case requires sub-functionalities Lower level Use Cases, UC fragments… … which are not real (“start-to-end”) use cases

Functional-like decomposition, not really object-oriented!

Hierarchical decomposition: relationships between use cases Inclusion Generalization (Extension)

Page 38: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 38

Formal UC DescriptionUC Decomposition: Inclusion

« include » stereotype The included use case is a

mandatory part of the including one

The including UC depends on the included one

HandleSession

« include »

VerifyCard

« include »

AuthenticateCustomer

« include »

Get CustomerInformation

HandleTransaction

« include »

Including

« include »

Included

Page 39: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 39

Formal UC Description UC Decomposition: Extension(1)

« extend » stereotype The extending use case

augments the functionality of the extended one,

The extending UC depends on the extended one

DeliverReceipt

« extend »

Extended

« extend »

Extending

HandleSession

« include »

VerifyCard

« include »

AuthenticateCustomer

« include »

Get CustomerInformation

HandleTransaction

« include »

Page 40: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 40

Formal UC DescriptionUC Decomposition: Extension(2)

The interpretation of « extend » varies The UML standard does not specify the nature of the

condition at the “extension point” Corporate policies may apply!

Note the direction of the dependency arrow The lower level (extending) use case depends on the

higher one The higher level one may not depend on the extension This remark helps to distinguish « extend » from

« include »

Page 41: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 41

Formal UC Description UC Decomposition: Generalization

The specialized and generalized use cases are in a “sort of” relationship

HandleTransaction

HandleDeposit

HandleWithdrawal

HandleConsult

HandleTransfer

Generalized

Specialized

Page 42: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 42

Formal UC Description Remark on Actors: Generalization

It may be convenient to apply generalization to actors

A frequent flyer and a regular passenger are both passengers

Each of them may play the (general) role of Passenger in a use case

However, e.g., a frequent flyer may interact with specific use cases

Passenger

FrequentFlyer

Regular

Page 43: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 43

Formal UC Description UC Decomposition: Cockburn's Style

Use Case: Handle SessionPrimary actor (initiator): CustomerSupporting actor: BankPrecondition: ATM is freePrimary Scenario Customer inserts the card into

ATM. ATM asserts card validity. Customer authenticates with ATM. ATM gets Customer information

from Bank. Customer performs a transaction. Customer quits. ATM ejects card , Customer takes itPostcondition: ATM is free and all

transactions have been recorded

HandleSession

« include »

VerifyCard

« include »

AuthenticateCustomer

« include »

Get CustomerInformation

HandleTransaction

« include »

Page 44: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 44

Formal UC DescriptionUC Decomposition: Best Practices

Avoid « extend » unless specific corporate policy!

Usually actors are not repeated on decomposed diagrams unless this can bring some added information…

Interaction of an actor with a specific sub-UC Interaction of a specialized actor with a sub-UC

or specific corporate policy! Do not over-decompose

Sub-UC should have “functional substance” (that is, in general, several significant sub-scenarios)

Page 45: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 45

Formal UC DescriptionUC Scenarios (1)

Scenarios are instances of use cases Natural language for expressing

scenarios has a strong power of expression lacks precision makes it difficult to express information like

timing and concurrency Need for formal (UML) expression of

scenarios and use cases

Page 46: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 46

Formal UC DescriptionUC Scenarios (2)

Sequence diagrams Only one scenario per diagram Accent on the time flow At the Use Case level, express scenarios involving

the system and some of its actors May be used also as a mean to model business

activity (inter-actor scenarios) Activity diagrams

Several scenarios (even a full use case) at once Sort of (concurrent) flow charts…

Page 47: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 47

Formal UC DescriptionUC Scenarios: Sequence Diagrams

: Customer : ATM : Bank

prompt for selection

select transaction

produce result

quit

insert card

get customer info

eject cardtime

Page 48: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 48

Formal UC DescriptionUC Scenarios: Activity Diagrams

(1)

Express a flow of control Composed of Action States (or Activities) connected

by Transitions Transitions may be conditional A Transition is fired if its origin Activity has

completed its action and if its (optional) condition is true

Verify Date [date OK]

Verify Code

condition

transition

action state

Page 49: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 49

Formal UC DescriptionUC Scenarios: Activity Diagrams

(2)

Verify Card

Authenticate Customer

Get Customer Info

Handle Transaction

EjectSwallow

[ not Card_OK ]

[ Card_OK ]

[ not Passed ]

[ Passed ]

[ not Quit ]

[ Quit ]

Handle Session UC

Page 50: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 50

Formal UC DescriptionUC Scenarios: Activity Diagrams

(3)

Fork and join bars Express concurrency Fork spawns several

concurrent activities Join waits for all incoming

activities to complete Logical concurrency

Avoid enforcing non relevant sequencing

The designer will have the freedom to choose how to implement (even in non-concurrent ways)

ProcessOrderUC Receive Order

Establish Invoice

Deliver

Prepare Delivery

Page 51: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 51

Formal UC DescriptionUC Scenarios: Activity Diagrams

(4)

Receive Order

Establish Invoice

Prepare Delivery

Deliver

Delivery DeptAccounting DeptUser Interface

ProcessOrderUC

Page 52: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 52

Formal UC DescriptionUC Scenarios: Activity Diagrams

(5)

Receive Order

Establish Invoice

Prepare Delivery

Deliver

Delivery DeptAccounting DeptUser Interface

ProcessOrderUC

Order

Invoice

Page 53: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 53

Formal UC DescriptionUC Scenarios: Activity Diagrams

(6)

Accent is on the flow of control Describe at once a full set of scenarios Describe concurrent operations Created objects and responsibilities of

objects may be represented They may become too complex Risk to do functional analysis

Page 54: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 54

Practice of Use Case ModelsOrganizing the Model

Use CaseModel

UC 1

UC 2

UC n

Top level UCdiagram

Sub UCdiagrams

W Scenario files

Activity diagrams

UC 1

UC 2

W

Use CaseModel

Sub Model 1

SubModel 2

Packagehierarchy

Page 55: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 55

Use Case ModelConclusion: Difficulty and Drawbacks

Use Case modeling is difficult Homogeneity, completeness, consistency…

UML “formalism” is simple, even simplistic No real semantics No formal description of textual scenarios Need for predefined interpretations, corporate policies

Textual scenarios awkwardly express complex control Loops, conditionals…

Page 56: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 56

Use Case ModelConclusion: Advantages

Simple to elaborate, understand, and communicate Even to non-computer scientists

Focus on user needs, not on solution or architecture Avoid architectural drift in object-orientation Ease traceability from functional needs to

implementation Facilitate setting up integration tests

From use cases, one can derive test cases

Page 57: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 57

Introduction to UML

Class and Object Modeling(Object-Oriented Analysis)

Page 58: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 58

Analysis Model

Object-orientation overview The elements of analysis models Class diagrams Realizing use cases and scenarios Practice of analysis models

Page 59: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 59

Object-Orientation OverviewA World of Objects

The (application) world is composed of objects These objects are linked together

Static relationships (links) These objects react to stimuli (messages)

Either internal or external Originating from other objects or from outside the system

These objects have an internal state Internal data (attributes) and status of the links with other

objects The state may change when the objects are stimulated

Page 60: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 60

Object = Identity + State + Behaviour

Objects should be distinguishableThe identity is independent from the state

Operations, events, messages…Public interfaceInternal data values

Status of links with other objects

Object-Orientation OverviewWhat's in an Object? (1)

Objects have “crisp” conceptual boundaries (Booch, 1994)

Page 61: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 61

Object-Orientation OverviewWhat is an Object? (2)

Static information: architectural aspect List of operations (interface)

The messages the object can accept and react to State values

Possible values of internal data (attributes) Possible links with other objects,

that are message transport media

Dynamic behaviour: control aspect State evolution and messages sent to other objects

Triggered by message flows

Page 62: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 62

Object-Orientation OverviewCandidates for Objects

Material (tangible) things

Cars, planes, devices, people…

Invoices, documents… More abstract things

Flights, transactions… People roles

Client, server, customer… Functions, processes

Reifying, objectifying… And many other things

Identity, state, behaviour depend on the application domain

Thus, object identification is relative to the application domain

Page 63: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 63

Object-Orientation OverviewAbstraction: Points of View

The system analyst should capture the view(s) of an object that is/are appropriate for the application and model them in a coherent way.

Page 64: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 64

Object-Orientation OverviewWhat's in a Class? (1)

A group of objects sharing common properties: common structure:

same attributes same possible relations with other objects

common behaviour: same operations An abstract data type A model to instantiate objects

A class defines the possible behaviours and the information structure of all its instances

Page 65: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 65

Object-Orientation OverviewWhat's in a Class? (2)

Different instances may have their operations activated in different ways, different sequences… Hence, they may be in different states

Different instances, even if they have the same attribute values, have different identities

Instance = a particular object belonging to a class

Class Car

Page 66: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 66

Object-Orientation OverviewWhat's in a Class? (3)

Class = Abstract Data Type (ADT)

ADT= value set + operations

Built-in types (integer, real, boolean)

User defined types

User defined types are treated as “first class citizen”

Copying objects, Passing objects as

parameters or return value,

Using operators on objects

Page 67: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 67

Object-Orientation OverviewLinks between Objects

The architecture of the object system Permanent (or semi-permanent) links

Examples A travel agency is connected to an airline consortium A car has wheels, engine, body… A PC is part of the Internet An invoice refers to a Customer John owns a Rolls Royce car John’s car is on the road to London Mary is employed by Amadeus Jacques married Bernadette

Page 68: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 68

Object-Orientation OverviewObject States

A car may be running, parked, or broken down

An order may be emitted, shipping, cancelled, completed, archived…

A flight may be on-time, delayed, cancelled, hijacked…

Jacques married Bernadette The existence of the wedding link induces a particular

state for both participants (each of them is married)

Page 69: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 69

Object-Orientation OverviewCommunication by Messages(1)

anOtherObjectInternal

data(attributes)

anObject

Internaldata

(attributes)

message(parameters)

(static) linkop1

op2

Page 70: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 70

Object-Orientation OverviewCommunication by Messages(2)

Usually asymmetric The emitter knows (designates) the receiver The receiver does not know the emitter

A message triggers an operation of the object The object may change state as a consequence of the

operation Usually a message and its associated operation bear

the same name Message may carry values (parameters)

Page 71: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 71

Object-Orientation OverviewCommunication by Messages(3)

Example: A travel agency reserves seat 3A for Mr Smith

on flight BA349 next monday

A Travel Agencyreserve(“3A”, “Mr. Smith”)Flight BA349 Monday xxx

reserve(seatid, name)

After reservation, the state of the flighthas changed (may be it became full?)

Page 72: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 72

The Elements of Analysis ModelsUse Case Model and Analysis Model

Use case model Language of the customer External view of the system Structured by use cases

Contract between customer and developer

May be (slightly) redundant or inconsistent

Describes the functionality

Defines use cases

Analysis model Language of the developer Internal view of the system Structured by stereotyped

classes and packages Used primarily by

developers, designers, programmers

Should not be redundant or inconsistent

Outlines a realization of the functionality

Defines use cases realization

Page 73: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 73

The Elements of Analysis ModelsUse Case Realization

Realizing a use case Finding classes collaborating for realizing the use case Finding their attributes and operations Finding relationships between these classes Refining the use case and scenarios description to take

the new classes into account A group of classes collaborating for

realizing a use case is called a Collaboration

collaborationuse case

Class1

Class2

Page 74: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 74

The Elements of Analysis ModelsDependency (1)

A semantic relationship between two things

When the target changes, the source might have to change

Generally unidirectional

Does not imply a static (permanent) kind of relationship

ProductDefinition

Model

AnalysisModel

PersonDocument

«create»

Page 75: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 75

The Elements of Analysis ModelsDependency (2)

Realization Semantic relationship between classifiers wherein one component specifies a contract that the other guarantees to carry out

Usually relationship between some interface and its implementation (in a broad sense)

collaborationuse case

ProductDefinition

Model

AnalysisModel

«realize»

Page 76: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 76

Analysis Model

Object-orientation overview The elements of analysis models Class diagrams Realizing use cases and scenarios Practice of analysis models

Page 77: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 77

Class Diagrams

Associations Generalization Generalization and aggregation Abstract classes and operations Stereotypical classes Constraints Best practices

Page 78: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 78

Class DiagramsClasses for the ATM

Card ATM interface

Session

Transaction TransactionRecord

CustomerInformation

Page 79: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 79

Class DiagramsClass, Attribute, and Operation

Personnameaddressmove()marry()

attributes

operations

nameData carried by each instanceof the class

Object behaviorOperations that can be applied toeach instance

Page 80: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 80

Class DiagramsAssociation and Link

Association

Link Instance of an

association

Man Womanwedlock

bill : Man

hilary : Woman

A structural relationship describing a set of links

Some special cases (aggregation, composition)

Generally implies mutual knowledge

Corresponds to stable or (semi-)permanent relationship

Page 81: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 81

Class DiagramsAttribute, Operation, Association

Personname : stringaddress: string

Companynamelocation hire(Person)dismiss(Person)

Operations may have typed arguments; they can be inferred from scenarios

Default values of attributes are possible

= mainpremisse

works in

Associations have a name

Attributes have a name (and a type)

Page 82: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 82

Class DiagramsInstance of a Class (Object)

Object (Instance)

bill : Person

name = “Bill Gates”address = “Redmond, WA”

Person

«instanceOf»

Jane : Person

name = “Jane B.”address = “Paris, FR”

«instanceOf»

Page 83: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 83

Class DiagramsAssociations: Names and Roles

Companyemploys

Person

Personparent

child

employer employee

role role

Page 84: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 84

Class DiagramsAssociations: Multiplicity (1)

Companyemploys

Person0..1 0..*

Manwedlock

Woman0..1 0..1

Personparent

child2

*

Page 85: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 85

Class DiagramsAssociations: Multiplicity (2)

from 1 to 4

C2exactly 2

C1..4

C1..* at least 1

C*0 or more (0..*)

C2, 4..7, 10..* 2, 4 to 7, 10 or more

C default is (exactly) 1

Page 86: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 86

Class DiagramsAssociations: Association as Class

Exactly one instance of class Job per link The life time of the association object is the same as the one of the link

Companyemploys

Person0..1

0..*

Jobsalaryfunctionpromote()

Page 87: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 87

Class DiagramsAssociations: Aggregation

Whole/Parts relationships "is part of", "is composed of" Antisymetric

Two forms Weak aggregation (simply Aggregation) Strong aggregation (Composition)

Page 88: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 88

Companyemploys

Person*

Family*

*

*

Class DiagramsAssociations: (Weak) Aggregation

Weak coupling Sharing is possible Lifetime of component is not dependent of

compositeAn instance of Person may be part of several families

An instance of Person may be employed by several companies

An instance of Personmay be both an employee and a familymember

Page 89: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 89

Strong coupling No sharing Life-time of component usually starts and ends with

composite

Class DiagramsAssociations: Composition

Car

Wheel Engine Body4 1 1

Stock

*

0..1 0..1here, cardinalityis at most 1

Page 90: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 90

Class DiagramsClass Diagram for the ATM

Cardis inserted into

ATM interface

Session

Transaction

0..1 0..1

*Transaction

Record

0..1 1

CustomerInformation

0..1 1

{ordered}*

Page 91: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 91

Class DiagramsGeneralization (1)

Transaction

Deposit Transfer

Withdrawal Consult

Page 92: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 92

Class DiagramsGeneralization (2)

Relationship Between classes No cardinality Anti-symmetric and transitive

"Is A", "Is A Sort Of" Substitutability principle

The sub-class depends on its base class(es) Support of generalization in UML

Multiple inheritance is supported Multiple classification indirectly & partially supported Dynamic classification is almost not supported

Page 93: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 93

Class DiagramsGeneralization: Substitutability

B derives from A Any instance of B is also an instance of A for any

purpose of an A Any instance of B may be substituted to an instance

of A B may

Add new properties to the ones inherited from A Redefine operations inherited from A

B cannot get rid of properties inherited from A

Page 94: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 94

Class DiagramsGeneralization: Polymorphism

Drawing

draw()

Figure

Circle Square

draw()

Ellipse

draw()

Rectangle

draw()

*components

for all fig in components {fig.draw()

}

Page 95: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 95

Class DiagramsGeneralization: Multiple Inheritance

Triangle

Figure

Ellipse Rectangle

Circle Square Isosceles TrRightAngled Tr

RightAngled Isosceles Tr

{overlapping}

Page 96: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 96

Class DiagramsAbstract Classes and Operations

(1)

Abstract class Class with no instances Usually at the top of a class

hierarchy Abstract operation

An operation without implementation (i.e., realization)

An abstract operation makes the whole class abstract

If derived classes do not define the operation implementation, they are also abstract

« abstract »Figure

« abstract » draw()

Figure

draw()

Page 97: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 97

Class DiagramsAbstract Classes and Operations

(2)

Figure

Circle Square

draw()

Ellipse

draw()

Rectangle

draw()

Abstract class(top of hierarchy)

Concrete classes

Page 98: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 98

Class DiagramsStereotypical Classes (1)

Entity class Long-lived (persistent)

information

Control class Coordination,

sequencing, control…

Boundary class Interaction between the

system and its actors

«entity»

«control»

«boundary»

Page 99: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 99

Class DiagramsStereotypical Classes (2)

Cardis inserted into

ATM interface

Session

Transaction

0..1 0..1

*Transaction

Record

0..1 1

CustomerInformation

0..1 1

{ordered}*

Page 100: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 100

Class DiagramsConstraints

Restrict, clarify, or specify the semantics of model elements Can be applied to any kind of model element

Constraints may be expressed by Free text Special constraint language (OCL) Constraints are enclosed within braces {}

Predefined constraints Type of constraints (stereotype, pre- and post

conditions…) Individual constraints

Page 101: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 101

Class DiagramsConstraints: Class Invariant

A condition that must be verified by any instance at any time

Adult

age: Integer

is_emancipated(): Boolean

«invariant» { age >= 18 or is_emancipated() }

Class atributeClass operation

(without side-effects)

Constraint stereotype

Page 102: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 102

Class DiagramsConstraints: Pre- and Post-Conditions

The operation contract The pre-condition must be

guaranteed by the client of the class

The post-condition is guaranteed by the class itself (provided that the pre-condition holds)

Man

marry(Person p)

Person

married: Booleangender: enum {M, F} marry(Person)

{ pre: not married and p.gender != #M post: married }

Page 103: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 103

Class DiagramsConstraints: Class Contract (1)

Before an operation Invariants and pre-condition must be true

After an operation Invariant and post-condition should be true

Generalization and constraints (substitutability) Ideally, a sub-class should also verify its base classes

invariants Ideally an operation overridden in a sub-class may

weaken the pre-condition and strengthen the post-condition of its base classe(s) (“Demand less, promise more” principle)

UML does not really enforce these rules

Page 104: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 104

Class DiagramsConstraints: Class Contract (2)

CarDealer

sell_with_trade_in()

DiscountCarDealer

sell_with_trade_in()

{ pre: old car less than 5 years old post: discount 10 % }

{ pre: old car less than 8 years old post: discount 15 % }

Page 105: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 105

Companyemploys

Person0..1*

manages *

Class DiagramsConstraints: Predefined Constraints

Companyemploys

Person0..1

*Unemployment

Agency0..1

*{ xor }

{ subset }0..1

Page 106: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 106

Class DiagramsBest Practices (1)

Avoid meaningless classes

No attributes nor operations

No significance with respect to the problem…

At the analysis level, classes represent abstraction of the application, they are not a programming hack to reuse code

RoundObject

Balloon

Ball

Wheel

Egg

SeaUrchin

Page 107: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 107

Class DiagramsBest Practices (2)

Avoid too big classes

Many attributes, many operations, not all of them are needed at a given time

Too many responsibilities, represent several abstractions…

Use inheritance, aggregation, association instead

Restauranttablescarddisheswaiterspatrons

seat(patron, table)add_dish(menu, dish)serve(waiter, table)numberOfMeals()

Restaurant

Table Waiter

Patron

numberOfMeals()

serve

Dish

Cardadd(dish)

seat(table)

*

*

*

Page 108: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 108

Class DiagramsBest Practices (3)

Avoid explicit special operations Set, get, constructors, destructors, assignments….

Attribute versus association Use attribute notation for primitive (non-object) types For objects prefer aggregation or even regular

association, with roles

Carcolor: Stringpower: Integer…

Personowner

Engine

Page 109: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 109

Vehicle Engine

Class DiagramsBest Practices (4)

Avoid explicit circular dependency

In particular a base class should not depend on its sub-classes

Beware of the “fragile base” class problem

Base

Deriv

«friend»

Base

Deriv

Bicycle

Page 110: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 110

Class DiagramsBest Practices (5)

Do not confuse dependency and association An association describes a relationship between instances An association usually implies mutual dependency

Form

FormWindow0..1

1Form

FormWindow

? indeed, but better …

This implies the diagram on the left, but adds information related to instances

Page 111: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 111

Class DiagramsBest Practices (6)

Avoid redundancies Do not represent the same information with two

different ways Attribute and association Redundant attributes

Manmy_wife: Woman

Womanwife

Personbirthday: Dateage: Integer

Page 112: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 112

Class DiagramsBest Practices (7)

At analysis level, avoid programming artifacts

Company Person*0..1

ListOfEmployees

Company Person*

0..1

*Company

listOfEmployees

Person

Also violate previous slide advice*

Page 113: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 113

Analysis Model

Object-orientation overview The elements ot analysis models Class diagrams Realizing use cases and scenarios Practice of analysis models

Page 114: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 114

Realizing Use Cases and Scenarios

Use Case realization as a Collaboration Realizing scenarios Sequence diagrams Collaboration diagrams Interaction diagrams: comparison Activity diagrams and objects Best practices

Page 115: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 115

Handle Session

Realizing UC and ScenariosUC Realization as Collaboration(1)

List all the classes (or roles) that together realize a given use case

Allow traceability from Use Case Model to Class Model

Session TransactionCustomer

Information

ATM interface

Page 116: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 116

Realizing UC and ScenariosUC Realization as Collaboration(2)

MVC pattern

Model

Controler

View

Collaboration Defines an interaction A society of roles,

objects, or other elements to provide some cooperative and synergic behavior

Possibly structural as well as behavioral

Used to model Patterns (design or analysis patterns)

Page 117: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 117

Realizing UC and ScenariosRealizing Scenarios (1)

The requirement scenarios do not involve objects (and classes) Except for actors There is a need to revisit the scenarios in the light of

the analysis classes The refined scenarios are part of the use case

realizations (collaborations) Using formalisms will

make descriptions more precise help the analysis work

Page 118: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 118

Realizing UC and ScenariosRealizing Scenarios (2)

“Scenario diagrams” Interaction diagrams: one scenario at

a time Sequence diagrams Collaboration diagrams

Activity diagrams: several scenarios (a full use case?)

Page 119: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 119

Realizing UC and ScenariosSequence Diagrams (1)

Describe one scenario Involve objects and messages (stimuli)

Messages exchanged between instances are called stimuli

A stimulus can be calling an operation (with possible parameters)

An operation is attached to a particular class An operation call is a synchronous communication

A stimulus can be sending a signal A signal is itself a classifier, a priori independent of classes Roughly speaking, the instances of a signal are its

occurrences Sending a signal is an asynchronous communication

Accent is on the time flow of events

Page 120: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 120

Realizing UC and ScenariosSequence Diagrams (2)

time

get_Customer_Information()

select_transaction(sel)

display_menu()

: Customer : Bank

quiteject_card

insert_card

: ATMInterface

: Session« create »

: Transaction« create »

display_menu()

ask_PIN()

enter_PIN(pin)

Page 121: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 121

Realizing UC and ScenariosSequence Diagrams (3)

: Customerinsert_card

: ATMInterface

: Session« create »

actor(optional)

stimulus(signal kind)

life line

transient object

permanent object

Page 122: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 122

Realizing UC and ScenariosSequence Diagrams (4)

get_Customer_Information()

select_transaction(sel)

display_menu()

: Customer : Bank: ATMInterface

: Session

: Transaction« create »

signal sent outof the system

function call

end of object life

stimulus(operation call with parameter)

begin of object life

Page 123: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:09 123

Realizing UC and ScenariosCollaboration Diagrams (1)

Describe one scenario Involve objects and messages (stimuli) Accent is on messages exchanged and

links between objects Do not confuse

Collaboration: the realization of a use case, which usually appears in a Use Case diagram

Collaboration diagram: a form of interaction diagram expressing a scenario

Page 124: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:10 124

Realizing UC and ScenariosCollaboration Diagrams (2)

: Customer

: ATMInterface

: Session

: Transaction

: Bank

4: 8: 13: 16:

5: enter_PIN(pin)9: select_transaction( sel)

14: quit( )2: <<create>>

3: ask_PIN( )7: display_menu( )12: display_menu( )

15: eject_card( )

6: get_Customer_Information( )

10: <<create>>

11:

Page 125: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:10 125

Realizing UC and ScenariosInteraction diagrams: Comparison (1)

Sequence and collaboration diagrams Common properties

For expressing scenarios in the analysis model, both forms are almost equivalent, although the focus is different

Only one scenario at a time Help to define necessary operations of classes The number of diagrams may become huge Risk of redundancy in the diagrams for scenarios with

only little variations (difficult to maintain) Some useful features are awkwardly represented (e.g.,

loops and conditionals)

Page 126: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:10 126

Realizing UC and ScenariosInteraction diagrams: Comparison (2)

Differences Sequence: temporal aspect (stress on

message/signal sequencing) Collaboration: architectural aspect (objects and

links, roles of objects…) For the design model, collaboration diagrams

may be richer Roles of objects Some form of concurrency Sequence nesting…

Page 127: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:10 127

Realizing UC and ScenariosBest Practices

Expressing use case and scenarios in the customer’s language (usually natural) remains mandatory

Do not use too much formalism! Avoid redundant scenario descriptions For instance, remember that sequence and collaboration

diagrams are equivalent and that is generally useless to use both to describe the same scenario

Also recall that activity diagrams contain several scenarios

Limit the number of objects, swimlanes, and interactions in diagrams

Page 128: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:10 128

Analysis Model

Object-orientation overview The elements ot analysis models Class diagrams Realizing use cases and scenarios Practice of analysis models

Page 129: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:10 129

Practice of Analysis ModelsOrganizing the Model

UC 1

UC 2

TheSystem

UC Model

Class diagrams

UC diagramsshowing Collaborations

Collaboration UC 1

UC 2

Interactiondiagrams

Collaboration

Class

Class

AnalysisModel

Page 130: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:10 130

Practice of Analysis ModelsModel Global Properties

Scenarios (and activity diagrams) should be attached to Use Case realizations (i.e., Collaborations)

All scenarios of interest should be represented in a “scenario diagram” It is almost impossible (not suitable?) to describe all

scenarios Completeness of the Analysis Model

Every Use Case should have its own realization (Collaboration) listing the classes that “implement” it

A class should be part of at least one UC realization (Collaboration)

Page 131: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:10 131

Practice of Analysis ModelsScenarios-Collaboration Completeness

A class contributing to a UC realization (Collaboration) should appear in at least one “scenario diagram”

If an instance appears in a “scenario diagram”, its class should be associated with the corresponding UC realization (Collaboration)

Page 132: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:10 132

Practice of Analysis ModelsInteraction-Class Completeness

A stimulus received by an object should be part of the interface of its class (it is usually one of its operations)

Ideally, public operations should appear in some “scenario diagram”

Page 133: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:10 133

Introduction to UML

State Modeling(Object-Oriented Analysis)

Page 134: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:10 134

State-Transition Diagrams

Attached to a class (with a reactive behaviour)

Describe the dynamic behaviour of any instance when receiving events

Relationships between events and states Deterministic finite state machines

Define the object states, their sequences, and the corresponding transitions

Express the control behaviour of an instance in any scenario where it may appear

Model borrowed from Harel’s StateCharts

Page 135: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:10 135

State and EventsEvents

Trigger state transitions An event can be

A stimulus: operation call or signal A stimulus originates from some object (possibly the

receiving one) An operation call requires some processing from the

receiving object A signal notifies some information; it is an object

A condition changing its truth value A watch dog elapsing

Events may carry value (parameters) Events have no duration

Page 136: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:10 136

State and EventsStates

Abstraction of attribute values and link status

The state of an object specifies The way it reacts to received events

A state specifies the events to which it is sensitive Some events may be ignored when in a state

The activities the object performs while in this state State duration is not null Two predefined sorts of states

Initial state: corresponds to an instance “creation” Final state: corresponds to an instance “destruction”

Page 137: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:10 137

State and EventsStates and Events Separation

Events separate states States separate events

state 2 state 4state 1 state 3 state 5

events

Page 138: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:10 138

State-Transition DiagramsStates

initial state

final state

do: activity()entry/action()exit/action()event/action()

State name

action(): some processing, with an ideally null duration;

usually corresponds to a (private) operation of the classactivity(): as action() except that it may have non-null duration

Activity to perform while in the state

Action to perform when leaving the state

Action to perform when entering the state

Action to perform in response to an eventwithout leaving the state

Page 139: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:10 139

State-Transition DiagramsStates and Transitions (1)

event(parameters)[guard] / action()^sends

State1

State2

transition

Boolean condition

Action performed whiletraversing the transition Signals sent to other objects

while traversing the transition

As usual in UML all items are optional:If no label, normal termination transition

Trigger part Action part

Page 140: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:10 140

State-Transition DiagramsStates and Transitions (2)

State entry The entry actions are

performed The do activity is started

While in state, wait for

Either the termination of the do activity (normal termination)

Or an event listed in a event/action clause

Or an event in the trigger part of an outgoing transition (preemption)

Normal termination If there exists a normal

termination transition the condition of which holds (or is absent), execute the exit actions and traverse transition

Otherwise keep waiting Event/action clause

Suspend the do activity, execute the action, and resume the do activity

Preemption Abort the do activity,

perform the exit actions, and take the transition

Page 141: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:10 141

State-Transition DiagramsStates and Transitions (3)

ST diagrams represent deterministic finite state machines

For a given state, its outgoing transitions must be exclusive If two outgoing transitions are triggered by the same

event (or no event at all), their guards must be exclusive UML state-machine model does not cope with

the problem of simultaneous events Events are supposed to be serialised prior to be delivered Hence two events cannot be simultaneous

Page 142: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:10 142

State-Transition DiagramsSimple ST Diagrams (1)

This diagram omits details of states and transitions: this does not mean they do not exist; this simply means they are not shown!

At gate

Taxiing

Taking off

Landing

Flying

Page 143: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:10 143

State-Transition DiagramsSimple ST Diagrams (2)

At gatedo: boarding()

Taxiingdo: reach_runway()

Taking offdo: take_off()

Landingdo: land()

Flyingdo: flollow_flight_plan()

go [boarding terminated]

clear_for_take_off[runway lined up]

airborne

/^ATC.request_for_landing

[speed < SLimit]

[gate free]

Page 144: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:10 144

State-Transition DiagramsSimple ST Diagrams (3)

White move Black move

Start

Time over Time over

Black win

stalemate

Null

checkmatestalemate

White win

checkmate

Page 145: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:10 145

State-Transition DiagramsSimple ST Diagrams (4)

Idle Visible

do: execute()cursor_move

/mark_selection()

Spontaneous transition(termination of do:)

button_down/display_menu()

button_up/erase_menu()

Page 146: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:10 146

State-Transition DiagramsHierarchical ST Diagrams (1)

Neutral BackwardB

NF N

Forward

1st 2nd 3rdup up

stop downdown

Page 147: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:10 147

State-Transition DiagramsHierarchical ST Diagrams (2)

The history pseudo-state memorises the current sub-state and forces its re-entry when re-entering the macro-state

Neutral BackwardN

N

Forward

F

H

1st 2nd 3rdup up

stop downdown

B

Page 148: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:10 148

State-Transition DiagramsST Diagrams with Swimlanes

do: refuel()

do: catering()

Wait for crew do: boarding()

do: check_aircraft()[crew arrived]

At terminal

Page 149: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:10 149

Introduction to UML

Annex 1A Brief Object-Oriented Glossary

Page 150: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:10 150

Object-Oriented Glossary(1)

Link Static relationship between

objects Provide infrastructure for

exchanging messages Object

Abstraction of a concept in the application world

Has crisp boundaries Owns a state, a behaviour,

and an identity Has links with other objects Exchanges messages with

them

Abstraction Separate usage information

from implementation details Modularity

Group semantically related things together

Encapsulation Hide unnecessary

information Message

Dynamic flow of information between objects

Need links to travel

Page 151: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:10 151

Object-Oriented Glossary (2)

Association Relationship between

classes, modelling links that the instances of the classes may have together

Model of the links between instances of classes

Links are instances of associations

Class Group of objects with

identical structure and behaviour

Model for a group of objects Defines a type

Type Set of values together with

legal operations on these values

Instance of a class Object following the model

provided by the class

Page 152: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:10 152

Object-Oriented Glossary(3)

Derived class Inherits from all members

(attributes and operations) of its super class

Can only add new members or redefine some operations

Abstract operation Only defines the signature

of an operation, not its implementation

Abstract class Has no instance Defines common

attributes and operations of a set of classes

Polymorphism Ability of related objects

to answer to the same message, while in different ways, depending on their class

Page 153: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:10 153

Introduction to UML

Annex 2Synopsis of UML Model Elements

Page 154: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:10 154

A Conceptual View of UML

Model elements Rules Common mechanisms A UML model

Page 155: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:10 155

Model Elements

ModelElement

Diagram

“Thing”

Relation

Abstractions, first-class citizen in the model

Tie "things" together

Group interesting collections of things and express (some of) their relationships

Page 156: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:10 156

Model ElementsSummary

ModelElement

Diagram

“Thing”

Use Case

Class

Interface

Collaboration

Active Class

Component

Node

RelationRealization

DependencyAssociationGeneralization

Class

Use Case

Collaboration

Deployment

Object

Sequence

State-Transition

ComponentActivity

Structural

BehaviouralOrganizationalAnnotational

InteractionState Machine

PackageNote

Page 157: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:10 157

Model ElementsExamples of “things” (1)

“Classifiers”: elements that may have instances

Place an orderA use case

Personnameaddressmove()marry()

A class

person.cppA component

FileServerA node

Page 158: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:10 158

Model ElementsExamples of “things” (2)

Packages The only

organisational element

Represent (a form of) sub-model

Hierarchical organisation Interpackage

dependencies

Multiple meanings Represent

phases/activities of the development process

Analysis model, design model, test model…

Represent parts of the system

User interface, data base access, librairies…

Mere storage for related model elements… aPackage

Page 159: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:10 159

Model ElementsExamples of “things” (3)

Notes Explanatory parts, comments May be attached to any modeling element Complement the model Free format, pseudo-code, constraint language,

formal notations…

ProductDefinition

Model

This is a package

Page 160: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:10 160

Model ElementsRelationships

Dependency A semantic relationship between two things When the target changes, the source might have to change

Realisation Semantic relationship between classifiers wherein one thing

specifies a contract that the other guarantees to carry out Association

A structural relationship describing a set of links Some special cases (aggregation, composition)

Generalisation Objects of the specialised thing are substitutable for objects

of the more general one

Page 161: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:10 161

A semantic relationship between two things

When the target changes, the source might have to change

Generally unidirectional

Does not imply a static (permanent) kind of relationship

Model ElementsRelationships: Dependency

FlightSimulation

Engine

UserInterface

Tom

«instanceOf»Person

Page 162: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:10 162

Dynamic

diagrams

Model ElementsDiagrams

Class diagramObject diagramUse case diagramSequence diagramCollaboration diagramStatechart diagramActivity diagramComponent diagramDeployment diagram

Static diagrams

Static (implementation) diagrams

Interaction diagrams

State-transition diagrams

Page 163: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:10 163

Rules

Well-formed model Rules for

Names Scopes Visibility Integrity Execution

Badly-formed models

Elided Incomplete Inconsistent

Badly-formed models cannot be avoided during the project life-cycle

Page 164: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:10 164

Common Mechanisms

Specifications (Usually textual-like) representations stating the

exact details of a model element (its properties) Adornments

Graphic or textual adornments supplying extra semantics

Extensibility mechanisms Stereotypes Tagged values Constraints

Page 165: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:10 165

Common MechanismsSpecifications

Specificationof a class

Page 166: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:10 166

A stereotype can be attached to any model element

UML1.*: No more than one stereotype per element

It qualifies (particularises) a model element semantics

Predefined and user-defined stereotypes

Common MechanismsStereotypes

FlightSimulation

Engine

UserInterface

«access»

«vendor library»

MFC

Page 167: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:10 167

Common MechanismsStereotypes & Adornments

« subsystem »Billing Billing

« model »Design Model Design Model

Stereotype

Graphicadornment

« abstract »Person

PersonTextual (font)adornment

Page 168: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:10 168

Common MechanismsTagged Values & Constraints

Tagged values and properties

Person{version = 1.0 author = jpr}

name {frozen}addressage

move() marry() single()

{pre: age > 18 and single()}

Constraints

Page 169: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:10 169

A UML Model

A set of Model Elements Hierarchical organisation owing to packages (Partially) visible through diagrams Consistent and complete Manipulable by tools, verifiable, modifable… Exchangeable (XML)

A UML model is not reducible to a set of diagrams

Page 170: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:10 170

A UML ModelRational Rose Representation

Modelrepresentationand browser

Diagrameditors

Documentationof current model element

Page 171: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:10 171

Introduction to UML

Annex 3Diagram Notations

Page 172: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:10 172

UML Diagrams

Requirement modeling, Design…

Design, Test, Configuration Management

Requirement modeling, Design

Design, Test, Simulation

Requirement modeling, Design, Test

Requirement modeling, Design, Test

Requirement modeling

Analysis, Design, Test…

Analysis and Design

Run-time organization, distribution…

Deployment

Software resource organization

Component

Business proceduresActivity

Dynamic behaviorStatechart

Cooperation between objects, Design Patterns

Collaboration

Scenario of use, exchange of messages between objects

Sequence

Application needsUse Case

Architecture of a particular instance of the model

Object

Architecture, structureClass

Page 173: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:10 173

Synopsis of Notations Use Case Diagrams

Page 174: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:10 174

Synopsis of Notations Class Diagrams

Page 175: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:10 175

Synopsis of Notations Object Diagrams

Page 176: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:10 176

Synopsis of Notations Sequence Diagrams

time

Page 177: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:10 177

Synopsis of Notations Activity Diagrams

Page 178: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:10 178

Synopsis of Notations State-Transition Diagrams

Page 179: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:10 179

Synopsis of Notations Component Diagrams

Page 180: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:10 180

Synopsis of Notations Deployment Diagrams

Page 181: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:10 181

Introduction to UML

References

Page 182: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:10 182

The Object-Oriented ApproachGenerality

Object-Oriented Software EngineeringIvar JacobsonAddison Wesley, 1993

Object Oriented Analysis and DesignGrady Booch2nd Edition, Addison Wesley, 1994

Object-Oriented Solutions

Grady BoochAddison Wesley, 1996

Object-Oriented Software ConstructionBertrand Meyer3rd Edition, Prentice Hall, 2000

Page 183: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:10 183

The Object-Oriented ApproachMethodology

The Unified Software Development ProcessIvar Jacobson, Grady Booch, James RumbaughAddison Wesley, 1999

Object Solutions: Managing the Object-oriented Project

Grady BoochAddison Wesley, 1996

Surviving Object-oriented ProjectsAlistair CockburnAddison Wesley, 1997

Page 184: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:10 184

The Unified Modeling LanguageTutorial Books

The Unified Modeling Language User Guide Grady Booch, James Rumbaugh, Ivar JacobsonAddison Wesley, 1999.

The Unified Modeling Language Reference GuideJames Rumbaugh, Grady Booch, Ivar Jacobson Addison Wesley, 1999

UML in a NutshellSinan Si AlhirO’Reilly, 1998

Page 185: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:10 185

The Unified Modeling LanguageUsing the UML

Visual Modeling with Rational Rose 2000 and UMLTerry Quatrani, Addison Wesley, 2000

Writing Efficient Use CasesAlistair Cockburn, Addison Wesley, 2001

Applying Use Cases: A Practical GuideGeri Schneider, Jason P. WintersAddison Wesley, 1998

UML DistilledMartin Fowler (with Kendall Scott)Addison Wesley, 1997

Page 186: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:10 186

Object-Oriented Approach & UMLMiscellaneous

The Object Constraint LanguageJos Warmer, Anneke KleppeAddison Wesley, 1999

Design Patterns: Elements of Reusable Object-oriented Software

Erich Gamma, Richard Helm, Ralph Johnson, John VlissidesAddison Wesley, 1995

Applying UML and Patterns, Craig Larman2nd Edition, Prentice Hall, 2002

Model Driven Architecture David S. Frankel

Wiley, 2003

Page 187: Introduction to UML, the  Unified Modeling Language

© 2004 Jean-Paul Rigault19/04/23 21:10 187

The Unified Modeling LanguageOfficial References

OMG Unified Modeling Language SpecificationObject Management Group, Inc.Version 1.5, 2003

URL's: http://www.omg.com http://www.rational.com/uml