Unified Modeling Language UML - Sophia - Inria · Unified Modeling Language UML Introduction. 2...

51
Unified Modeling Language UML Introduction

Transcript of Unified Modeling Language UML - Sophia - Inria · Unified Modeling Language UML Introduction. 2...

Page 1: Unified Modeling Language UML - Sophia - Inria · Unified Modeling Language UML Introduction. 2 Charles André - UNSA What is UML and what is it for? UML is a language for – Visualizing

Unified Modeling LanguageUML

Introduction

Page 2: Unified Modeling Language UML - Sophia - Inria · Unified Modeling Language UML Introduction. 2 Charles André - UNSA What is UML and what is it for? UML is a language for – Visualizing

Charles André - UNSA2

What is UML and what is it for?

UML is a language for– Visualizing– Specifying– Constructing– Documenting

Syntax, Semantics (verification)

GraphicsArchitecture and behaviorAllow code generationTextual and graphical

descriptions

the artifacts of a software-intensive system

From now on, slides from B. Selic [3]

Page 3: Unified Modeling Language UML - Sophia - Inria · Unified Modeling Language UML Introduction. 2 Charles André - UNSA What is UML and what is it for? UML is a language for – Visualizing

Charles André - UNSA3

UML: Evolution

Page 4: Unified Modeling Language UML - Sophia - Inria · Unified Modeling Language UML Introduction. 2 Charles André - UNSA What is UML and what is it for? UML is a language for – Visualizing

Charles André - UNSA4

UML 2 Language ArchitectureA core language + a set of optional “language units”

Some language units have multiple incrementsMultiple levelsof compliance

Page 5: Unified Modeling Language UML - Sophia - Inria · Unified Modeling Language UML Introduction. 2 Charles André - UNSA What is UML and what is it for? UML is a language for – Visualizing

Charles André - UNSA5

UML 2: Run-Time SemanticsMuch more than a notation

Page 6: Unified Modeling Language UML - Sophia - Inria · Unified Modeling Language UML Introduction. 2 Charles André - UNSA What is UML and what is it for? UML is a language for – Visualizing

Charles André - UNSA6

How things happen in UMLIn UML, all behavior results from the actions of (active) objects

Object behavior(e.g., statechart)

Inter-objectbehavior

(interaction)

Page 7: Unified Modeling Language UML - Sophia - Inria · Unified Modeling Language UML Introduction. 2 Charles André - UNSA What is UML and what is it for? UML is a language for – Visualizing

Charles André - UNSA7

UML approach: Single ModelViews are projections of a complete model

Continuous integration of views with dynamic detection of inconsistencies

Page 8: Unified Modeling Language UML - Sophia - Inria · Unified Modeling Language UML Introduction. 2 Charles André - UNSA What is UML and what is it for? UML is a language for – Visualizing

Charles André - UNSA8

UML 2 Diagram Types

UML Diagram

Structure Diagram

Behavior Diagram

Class Diagram

Instance Diagram

Package Diagram

Deployment Diagram

Composite Structure

Collaboration Diagram

Statechart Diagram

Activity Diagram

UseCase Diagram

Interaction Diagram

InteractionOverview

Timing Diagram

Communication Diagram

Sequence Diagram

The different diagram types of UML represent different views of a given system typically based on different viewpoints or representations

Page 9: Unified Modeling Language UML - Sophia - Inria · Unified Modeling Language UML Introduction. 2 Charles André - UNSA What is UML and what is it for? UML is a language for – Visualizing

Charles André - UNSA9

Object-Orientation OverviewThe (application) world is composed of objectsThese objects are linked together

Static relationships (links)

These objects react to stimuli (messages)Either internal or externalOriginating from other objects or from outside the

system

These objects have an internal stateInternal data (attributes) and status of the links with

otherThe state may change when the objects are stimulated

Page 10: Unified Modeling Language UML - Sophia - Inria · Unified Modeling Language UML Introduction. 2 Charles André - UNSA What is UML and what is it for? UML is a language for – Visualizing

Charles André - UNSA10

What is an object?Object = Identity + State + Behavior

Objects should bedistinguishableThe identity is independent of the state

Internal data valuesStatus of links with otherobjects

Operations,events, messages…

Public interface

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

Page 11: Unified Modeling Language UML - Sophia - Inria · Unified Modeling Language UML Introduction. 2 Charles André - UNSA What is UML and what is it for? UML is a language for – Visualizing

Charles André - UNSA11

What is an object? Static information: architectural aspects

– 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 behavior: control aspect– State evolution and messages sent to other

objects• Triggered by message flows

Page 12: Unified Modeling Language UML - Sophia - Inria · Unified Modeling Language UML Introduction. 2 Charles André - UNSA What is UML and what is it for? UML is a language for – Visualizing

Charles André - UNSA12

What is in a Class?A group of objects sharing common

properties– common structure:

• same attributes• same possible relations with other objects

– common behavior: same operations

An abstract data typeA model to instantiate objects

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

Page 13: Unified Modeling Language UML - Sophia - Inria · Unified Modeling Language UML Introduction. 2 Charles André - UNSA What is UML and what is it for? UML is a language for – Visualizing

Charles André - UNSA13

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 14: Unified Modeling Language UML - Sophia - Inria · Unified Modeling Language UML Introduction. 2 Charles André - UNSA What is UML and what is it for? UML is a language for – Visualizing

Charles André - UNSA14

Model Elements: Summary

ModelElement

Diagram

“Thing”

Use Case

ClassInterfaceCollaboration

Active ClassComponentNode

RelationRealization

DependencyAssociationGeneralization

ClassUse CaseCollaboration

Deployment

ObjectSequenceState-TransitionComponent

Activity

Structural

BehavioralOrganizationalAnnotational

InteractionState Machine

PackageNote

Page 15: Unified Modeling Language UML - Sophia - Inria · Unified Modeling Language UML Introduction. 2 Charles André - UNSA What is UML and what is it for? UML is a language for – Visualizing

UML: Diagrammes de Classes

Transparents inspirés de [4]

Page 16: Unified Modeling Language UML - Sophia - Inria · Unified Modeling Language UML Introduction. 2 Charles André - UNSA What is UML and what is it for? UML is a language for – Visualizing

Charles André - UNSA16

Diagrammes de classes• Les diagrammes de classes représentent

un ensemble de classes, d'interfaces et de collaborations, ainsi que leurs relations. Ce sont les diagrammes les plus fréquents dans la modélisation des systèmes àobjets. Ils présentent la vue de conception statique d'un système. Les diagrammes de classes, (qui comprennent aussi les classes actives), présentent la vue de processus statique d'un système.

Page 17: Unified Modeling Language UML - Sophia - Inria · Unified Modeling Language UML Introduction. 2 Charles André - UNSA What is UML and what is it for? UML is a language for – Visualizing

Charles André - UNSA17

Les classes• La classe est une description

abstraite d’un ensemble d’objets• La classe peut être vue comme la

factorisation des éléments communs à un ensemble d’objets

• La classe décrit le domaine de définition d’un ensemble d’objets

• Description conceptuellement sépa-rée en deux parties– La spécification d’une classe qui décrit

le domaine de définition et les propriétés des instances de cette classe (type de donnée)

– La réalisation qui décrit comment la spécification est réalisée

• Caractéristiques des classes– Attributs– Opérations– Réceptions– Relations– Multiplicité– Persistance– Composant

Page 18: Unified Modeling Language UML - Sophia - Inria · Unified Modeling Language UML Introduction. 2 Charles André - UNSA What is UML and what is it for? UML is a language for – Visualizing

Charles André - UNSA18

Eléments graphiques

parametre

classe parametrable

une classe une autre classe

nom de l’association

nom de la classe association

attributsoperations

une classe une autre classe

nom de l’association

/ association dérivée

rôle 1 rôle 2

nom de la classe

attributsnom_attr : type = valeur initiale

opérationsnom_op (arg_list):type

nom de la classe

- variable privée+ variable publique# variable protégée

- opération privée+ opération publique# opération protégée

Remarque: Commencer le nom d’une classe par une majuscule

Page 19: Unified Modeling Language UML - Sophia - Inria · Unified Modeling Language UML Introduction. 2 Charles André - UNSA What is UML and what is it for? UML is a language for – Visualizing

Charles André - UNSA19

Visibilité des attributs et opérations• Public +

Visible à l’extérieur de la classe

• Protected #Visible seulement par

les descendants

• Private -Visible à l’intérieur des

méthodes

• Package ~

• Soulignéattribut/opération de

classe (statique)

Page 20: Unified Modeling Language UML - Sophia - Inria · Unified Modeling Language UML Introduction. 2 Charles André - UNSA What is UML and what is it for? UML is a language for – Visualizing

Charles André - UNSA20

Relations• L’association

• L’agrégation• La composition

• La généralisation• La dépendance

• L’association exprime une connexion sémantique bidirectionnelle entre classes

• Une association est une abstraction des liens qui existent entre les objets instances des classes associées

Page 21: Unified Modeling Language UML - Sophia - Inria · Unified Modeling Language UML Introduction. 2 Charles André - UNSA What is UML and what is it for? UML is a language for – Visualizing

Charles André - UNSA21

Exemple

Page 22: Unified Modeling Language UML - Sophia - Inria · Unified Modeling Language UML Introduction. 2 Charles André - UNSA What is UML and what is it for? UML is a language for – Visualizing

Charles André - UNSA22

Nommage des associations• Indication du sens de lecture

Page 23: Unified Modeling Language UML - Sophia - Inria · Unified Modeling Language UML Introduction. 2 Charles André - UNSA What is UML and what is it for? UML is a language for – Visualizing

Charles André - UNSA23

Nommage des rôles

•Le rôle décrit une extrémité d’une association

Page 24: Unified Modeling Language UML - Sophia - Inria · Unified Modeling Language UML Introduction. 2 Charles André - UNSA What is UML and what is it for? UML is a language for – Visualizing

Charles André - UNSA24

Multiplicité des rôles

1 Un et un seul0..1 Zéro ou unM .. N De M à N (entiers naturels)* Plusieurs0 .. * De zéro à plusieurs1 .. * D'un à plusieurs

Page 25: Unified Modeling Language UML - Sophia - Inria · Unified Modeling Language UML Introduction. 2 Charles André - UNSA What is UML and what is it for? UML is a language for – Visualizing

Charles André - UNSA25

Visibilité des rôles• Public• Protégé• Private

Page 26: Unified Modeling Language UML - Sophia - Inria · Unified Modeling Language UML Introduction. 2 Charles André - UNSA What is UML and what is it for? UML is a language for – Visualizing

Charles André - UNSA26

Navigabilité• étant donnée une association non

décorée entre deux classes, on peut naviguer d'un type d'objet vers un autre type d'objet.

• par défaut une association est navigable dans les deux sens.

• une indication de navigabilitésuggère en général qu'à partir d'un objet à une extrémité on peut directement et facilement atteindre l'un des objets à l'autre extrémité.

• lors d'une mise en œuvre programmée, ceci peut suggérer par exemple qu'un objet source mémorise une référence directe aux objets cible.

• étant donné un utilisateur, on désire pouvoir accéder à ses mots de passe

• étant donné un mot de passe, on ne souhaite pas pouvoir accéder à l'utilisateur correspondant

Page 27: Unified Modeling Language UML - Sophia - Inria · Unified Modeling Language UML Introduction. 2 Charles André - UNSA What is UML and what is it for? UML is a language for – Visualizing

Charles André - UNSA27

Exemple

Page 28: Unified Modeling Language UML - Sophia - Inria · Unified Modeling Language UML Introduction. 2 Charles André - UNSA What is UML and what is it for? UML is a language for – Visualizing

Charles André - UNSA28

L’agrégation

• Connexions sémantiques bidirectionnelles antisymétriques

• Forme d’association qui exprime un couplage plus fort entre classes

• Représentation des relations – maître et esclaves– tout et parties

– composé et composant.

Page 29: Unified Modeling Language UML - Sophia - Inria · Unified Modeling Language UML Introduction. 2 Charles André - UNSA What is UML and what is it for? UML is a language for – Visualizing

Charles André - UNSA29

La composition• Modélisation de la

composition physique– Multiplicité au max de

1 du coté de l’agrégat– Propagation

automatique de la destruction

Compagnie

Département

*

1Le tout

La partie

Page 30: Unified Modeling Language UML - Sophia - Inria · Unified Modeling Language UML Introduction. 2 Charles André - UNSA What is UML and what is it for? UML is a language for – Visualizing

Charles André - UNSA30

Hiérarchie de classes

• Gérer la complexité– Arborescences

de classes d’abstraction croissante

Sous-classe

Super-classe

Classe plusgénérale

Classe plusspécialisée

Page 31: Unified Modeling Language UML - Sophia - Inria · Unified Modeling Language UML Introduction. 2 Charles André - UNSA What is UML and what is it for? UML is a language for – Visualizing

Autres concepts présents dans les diagrammes de classes

Page 32: Unified Modeling Language UML - Sophia - Inria · Unified Modeling Language UML Introduction. 2 Charles André - UNSA What is UML and what is it for? UML is a language for – Visualizing

Charles André - UNSA32

Dépendances• Relation très générale (peut être utilisée entre

n’importe quel NamedElement).• Entre classes: la classe B dépend de la classe

A. Si A change, B peut changer; mais pas l’inverse.

Remarque: Les dépendances sont souvent stéréotypées

Page 33: Unified Modeling Language UML - Sophia - Inria · Unified Modeling Language UML Introduction. 2 Charles André - UNSA What is UML and what is it for? UML is a language for – Visualizing

Retour sur les attributs (1)• Les attributs peuvent

– Inlined attributes– Attributes by relationship

• Il n’y a pas de différence sémantique entre les deux

• Remarque: Avec les relations on peut introduire plus d’information (e.g., composition)

Charles André - UNSA33

Page 34: Unified Modeling Language UML - Sophia - Inria · Unified Modeling Language UML Introduction. 2 Charles André - UNSA What is UML and what is it for? UML is a language for – Visualizing

Retour sur les attributs (2)

• Notation générale des inlined attributesvisibility / name : type multiplicity = default

{ property strings and constraints }

visibility ::= + | - | # | ~

multiplicity ::= [ lower .. upper ]

/ indique que l’attribut est dérivé. Sa valeur peut être calculée àpartir des autres attributs de la classe.

Charles André - UNSA34

Page 35: Unified Modeling Language UML - Sophia - Inria · Unified Modeling Language UML Introduction. 2 Charles André - UNSA What is UML and what is it for? UML is a language for – Visualizing

Retour sur les attributs (3)• Attribute multiplicity:

quand plus qu’un, on peut préciser en plus{ ordered, unique }Défaut: unique, non ordonné

• Attribute properties:– readOnly– union– subsets attribute-name

– redefines attribute-name

Charles André - UNSA35

Page 36: Unified Modeling Language UML - Sophia - Inria · Unified Modeling Language UML Introduction. 2 Charles André - UNSA What is UML and what is it for? UML is a language for – Visualizing

Contraintes• Les contraintes

représentent des restrictions imposées sur un élément.

• Exprimées en langage naturel ou en langage formel (e.g., OCL)

• Notation: la contrainte est placée entre { } après l’éléments contraint ou dans une note.

Charles André - UNSA36

Page 37: Unified Modeling Language UML - Sophia - Inria · Unified Modeling Language UML Introduction. 2 Charles André - UNSA What is UML and what is it for? UML is a language for – Visualizing

Retour sur les opérations

Charles André - UNSA37

• Notationvisibility name ( parameters ) : return-type

{ properties and constraints }

visibility ::= + | - | # | ~

parameter ::= direction param-name type multiplicity = default-value { properties }

direction ::= in | out | inout | return

multiplicity ::= [ lower .. upper ]

• Operation constraints– preconditions state before invocation

– postconditions state after execution

– body conditions constraints on the returned value

– query does not modify the state of the class

Page 38: Unified Modeling Language UML - Sophia - Inria · Unified Modeling Language UML Introduction. 2 Charles André - UNSA What is UML and what is it for? UML is a language for – Visualizing

Charles André - UNSA38

Objet• Un objet est une instance de classe.• Chaque instance peut avoir un nom ou bien être

anonyme. Le nom (s’il est donné) est suivi de : et son type (souvent une classe).

Une classe

Une instance de la classe Car

Remarque: commencer le nom d’une instance par une minuscule

Page 39: Unified Modeling Language UML - Sophia - Inria · Unified Modeling Language UML Introduction. 2 Charles André - UNSA What is UML and what is it for? UML is a language for – Visualizing

Charles André - UNSA39

Classe abstraite• Une classe abstrait est utile pour identifier

des fonctionnalités communes à plusieurs types d’objets.

• Notation: Le nom d’une classes abstraite est écrit en italique.

• Une classe abstraite ne peut pas être instanciée. Elle doit être sous-classée(spécialisée). Les sous-classes concrètes peuvent être instanciées.

Page 40: Unified Modeling Language UML - Sophia - Inria · Unified Modeling Language UML Introduction. 2 Charles André - UNSA What is UML and what is it for? UML is a language for – Visualizing

Charles André - UNSA40

Les classes-associations (1)•Ajout d’attributs ou d’opérations dans la relation

Personne Sociétéemployé

* 0..2

Emploisalaire

augmenter()

société

Le nom de la classe correspond au nom de l’association(problème: il faut choisir entre forme nominale et forme verbale)

Attention: Pour une association donnée, un couple d'objets ne peut être connectés que par un seul lien correspondant à cette association.(sauf si l'association est décorée par {nonunique} en UML2.0)

Page 41: Unified Modeling Language UML - Sophia - Inria · Unified Modeling Language UML Introduction. 2 Charles André - UNSA What is UML and what is it for? UML is a language for – Visualizing

Charles André - UNSA41

Classes-associations (2)

Emploisalaire

Personne Sociétéemployé

1 1

0..2 société*

Ci-dessus, une personne peut avoir deux emplois dans la même société

e2

p1 s1e1

Personne Sociétéemployé

* 0..2

Emploisalaire

sociétés

Ci-dessus, une personne peut avoir deux emplois, mais pas dans la même société

p1 s1

e1

Page 42: Unified Modeling Language UML - Sophia - Inria · Unified Modeling Language UML Introduction. 2 Charles André - UNSA What is UML and what is it for? UML is a language for – Visualizing

Charles André - UNSA42

Associations qualifiées• Une association qualifiée met en relation deux classes sur

la base d'une clef.• La technique associée de mise en œuvre est souvent un

tableau associatif ou un dictionnaire.

Repertoire Fichiernom0..1

"Pour un répertoire, à un nom donné on associe qu'un fichier (ou 0 s'il existe aucun fichier de ce nom dans ce répertoire)."

Correspond à la notion intuitive d'index absente ci-dessous

Repertoire Fichier*

Page 43: Unified Modeling Language UML - Sophia - Inria · Unified Modeling Language UML Introduction. 2 Charles André - UNSA What is UML and what is it for? UML is a language for – Visualizing

Charles André - UNSA43

Interfaces (1)

• Une interface est un classeur (classifier) qui des déclarations de propriétés et d’opérations mais pas d’implémentations.

• On peut utiliser des interfaces pour grouper des éléments communs à plusieurs classeurs et fournir un contrat qu’un classeur qui implémente l’interface doit respecter.

• Assez proche du concept d’interface en Java.

Page 44: Unified Modeling Language UML - Sophia - Inria · Unified Modeling Language UML Introduction. 2 Charles André - UNSA What is UML and what is it for? UML is a language for – Visualizing

Charles André - UNSA44

Interfaces (2)

Class that implementsthe interface

Class that uses the interface Other notation: ball(provided interface)

And socket (requiredinterface)

Page 45: Unified Modeling Language UML - Sophia - Inria · Unified Modeling Language UML Introduction. 2 Charles André - UNSA What is UML and what is it for? UML is a language for – Visualizing

Charles André - UNSA45

Templates• UML permet d’utiliser des abstractions pour les types

de classes avec lesquels une classes peut interagir.

Templated class

Explicit template binding

Implicit template binding

Page 46: Unified Modeling Language UML - Sophia - Inria · Unified Modeling Language UML Introduction. 2 Charles André - UNSA What is UML and what is it for? UML is a language for – Visualizing

Classifier• A classifier is a classification of instances, it

describes a set of instances that have features(structural and/or behavioral) in common.

• Kinds of Classifiers: Class, Actor, Component, DataType, Interface, Node, Signal, Subsystem, UseCase,…

• Classes are the most general kind of classifiers. Other can be intuitively understood as similar to classes, with certain restrictions on content or usage. (Excerpts from [B2])

• Note that Classifier is an abstract metaclass

Charles André - UNSA46

Page 47: Unified Modeling Language UML - Sophia - Inria · Unified Modeling Language UML Introduction. 2 Charles André - UNSA What is UML and what is it for? UML is a language for – Visualizing

Data types• A data type is a type whose instances are identified only

by their value. A DataType may contain attributes to support the modeling of structured data types.

Charles André - UNSA47

Danger:A metamodel, not a user’s

model

• All copies of an instance of a data type and any instances of that data type with the same value are considered to be the same instance. Value ≠ Object

Page 48: Unified Modeling Language UML - Sophia - Inria · Unified Modeling Language UML Introduction. 2 Charles André - UNSA What is UML and what is it for? UML is a language for – Visualizing

Enumeration• A data type whose instances form a list of

named literal values.

• An enumeration is a user-definable data type.

Charles André - UNSA48

Page 49: Unified Modeling Language UML - Sophia - Inria · Unified Modeling Language UML Introduction. 2 Charles André - UNSA What is UML and what is it for? UML is a language for – Visualizing

Charles André - UNSA49

Bibliographie• [1] UML superstructure v 2.1.1, Feb. 2007

(http://www.omg.org/cgi-bin/doc?formal/07-02-05)

• [2] UML infrastructure v 2.1.1, Feb. 2007 (http://www.omg.org/cgi-bin/doc?formal/07-02-06)

• [3] Bran Selic. UML2 and SysML: Modeling LanguageStndards for System Design. IBM, 2007

• [4] Jean Bézivin. Ingénierie des modèles logiciels. Cours #1. Nantes 2003.

• [5] Jean-Marie Favre. UML Diagrammes de Classes –

Concepts avancés. Cours.

Charles André - UNSA49

http://www-adele.imag.fr/~jmfavre

Page 50: Unified Modeling Language UML - Sophia - Inria · Unified Modeling Language UML Introduction. 2 Charles André - UNSA What is UML and what is it for? UML is a language for – Visualizing

Charles André - UNSA50

Books• [B1] The Unified Modeling Language User Guide

Grady Booch, James Rumbaugh, Ivar JacobsonAddison Wesley, 1999.

• [B2] The Unified Modeling Language Reference GuideJames Rumbaugh, Grady Booch, Ivar Jacobson Addison Wesley, 1999

• [B3] Real-Time UMLDouglass B.P., Addison-Wesley, 1998.

• [B4] Doing Hard TimeDouglass B.P., Addison-Wesley, 1999.

• [B5] Real-Time Design PatternsDouglass B.P., “Addison-Wesley, 2003.

Page 51: Unified Modeling Language UML - Sophia - Inria · Unified Modeling Language UML Introduction. 2 Charles André - UNSA What is UML and what is it for? UML is a language for – Visualizing

Charles André - UNSA51

Books (continued)