uml : diagramme de classes
DESCRIPTION
UML : DIAGRAMME DE CLASSES. UML : DIAGRAMME DE CLASSES. APPROCHE OBJET: Représentation d’un concept ou d’une chose , ayant des limites et un sens dans un contexte donné. Physique ou Abstraite Caractéristiques : Informations Identifiant Comportement Messages - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: UML : DIAGRAMME DE CLASSES](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56816498550346895dd66f0f/html5/thumbnails/1.jpg)
UML : DIAGRAMME DE CLASSES
![Page 2: UML : DIAGRAMME DE CLASSES](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56816498550346895dd66f0f/html5/thumbnails/2.jpg)
UML : DIAGRAMME DE CLASSES
APPROCHE OBJET: • Représentation d’un concept ou d’une chose, ayant des limites et un sens dans un contexte donné.• Physique ou Abstraite• Caractéristiques :
• Informations• Identifiant• Comportement• Messages • Encapsulation
![Page 3: UML : DIAGRAMME DE CLASSES](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56816498550346895dd66f0f/html5/thumbnails/3.jpg)
UML : DIAGRAMME DE CLASSES
CARACTERISTIQUES :
• Informations : attributs décrivant l’objet
• Identifiant : permet d’individualiser les objets entre eux
• Comportement : implémenter sous forme de « méthodes »
• Messages : moyen de communication entre objets
• Encapsulation : gestion des accés
![Page 4: UML : DIAGRAMME DE CLASSES](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56816498550346895dd66f0f/html5/thumbnails/4.jpg)
UML : DIAGRAMME DE CLASSES
DEFINITION :
• Classe :modélisation de l’ensemble des objets ayant :
• attributs similaires• comportement en commun• relations communes avec d’autres objets
« Objet »
‘Titre d’objet’: ‘Titre de classe’ Les Miséra-bles
Les fleursdu mal
<< objet >>
Œuvre littéraire
<< classe >>
![Page 5: UML : DIAGRAMME DE CLASSES](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56816498550346895dd66f0f/html5/thumbnails/5.jpg)
UML : DIAGRAMME DE CLASSES
NOTATION :
• Tout nom de classe commence par une majuscule
NomAttribut : type = ValeurInitialeNomOpération(ListeArguments) : typeRetour
NomClasseattributs
opérations
![Page 6: UML : DIAGRAMME DE CLASSES](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56816498550346895dd66f0f/html5/thumbnails/6.jpg)
UML : DIAGRAMME DE CLASSES
ATTRIBUT :
• Donnée gérée par la classe (donc pour toutes les instances)• Valeur unique par instance (mais la même peut être dans plusieurs occurrences)• Identifiant est un attribut :
• particulier, autant de valeurs que d’instances• valeurs déterminent les instances de la classe
LIVRE
RéférenceNombre de pageEtat PrêtéDate du prêt en coursDate de restitution
![Page 7: UML : DIAGRAMME DE CLASSES](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56816498550346895dd66f0f/html5/thumbnails/7.jpg)
UML : DIAGRAMME DE CLASSES
OPERATIONS - METHODES:
• Opération : effectuée par l’objet• Méthode : effectuée par la classe• Signature (notation) : NomOperation(arg1,arg2) : TypeOutput• Comportement : effets observables des opérations
LIVRE
RéférenceNombre de pageDate du prêt en cours
Créer(arg1,arg2…) : boolPrêter(arg1,arg2…) : bool
![Page 8: UML : DIAGRAMME DE CLASSES](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56816498550346895dd66f0f/html5/thumbnails/8.jpg)
UML : DIAGRAMME DE CLASSES
OPERATIONS :
• Peut : • Accéder à ses propres attributs• Invoquer une autre opération de son propre objet• Invoquer une autre opération d’un autre objet (même classe ou autre classe)
• Ne peut pas: • Accéder directement aux attributs d’un autre objet
![Page 9: UML : DIAGRAMME DE CLASSES](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56816498550346895dd66f0f/html5/thumbnails/9.jpg)
UML : DIAGRAMME DE CLASSES
LIENS & ASSOCIATIONS:
• Lien : • connexion physique ou conceptuelle entre instances de classes
• Association: • Instance du lien (ex : rédiger, créer)
• Rôle : • Spécifie la contribution (ex : être rédigée par)
• Notation :• Nom : verbe• Navigation : via flèche
Par défaut : 2 sens
![Page 10: UML : DIAGRAMME DE CLASSES](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56816498550346895dd66f0f/html5/thumbnails/10.jpg)
UML : DIAGRAMME DE CLASSES
TYPES ASSOCIATIONS:
• Association binaire : associe 2 classes
OEUVRE
créer
AUTEUR
![Page 11: UML : DIAGRAMME DE CLASSES](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56816498550346895dd66f0f/html5/thumbnails/11.jpg)
UML : DIAGRAMME DE CLASSES
TYPES ASSOCIATIONS:
• Association n-aire : associe plus de 2 classes
PERSONNE PROJET
FONCTIONaffecter
![Page 12: UML : DIAGRAMME DE CLASSES](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56816498550346895dd66f0f/html5/thumbnails/12.jpg)
UML : DIAGRAMME DE CLASSES
TYPES ASSOCIATIONS:
• Association réflective : associe une classe à elle même
Dans ce cas, indispensable de nommer les associations (rôles)
UE ANNEE
associer
Être pré requis de
A pour pré requis
![Page 13: UML : DIAGRAMME DE CLASSES](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56816498550346895dd66f0f/html5/thumbnails/13.jpg)
UML : DIAGRAMME DE CLASSES
CLASSE D’ASSOCIATION: • Définition : classe liée à une association• Classe qui a les caractéristiques d’une association ou Association qui a les caractéristiques d’une classe.• Nécessaire quand attributs ou opérations liées à l’ensemble des classes de l’association• Utile pour simplifier
ARTICLE ENTREPOT
Quantité stockée
stocker
0..*0..*Numéro entrepôtNom entrepôt
Référence articleLibellé article
![Page 14: UML : DIAGRAMME DE CLASSES](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56816498550346895dd66f0f/html5/thumbnails/14.jpg)
UML : DIAGRAMME DE CLASSES
MULTIPLICITES (cardinalités):
1 Un et un seul
0..1 Zéro ou Un
M..N De M à N (entiers naturels)
0..* De Zéro à plusieurs
*
1..* De Un à plusieurs
N Exactement N (entier naturel)PERSONNE
SERVICE
ratta
cher
à
dirig
er
prêt
er
0 .. 1
1 .. *1 *
0 .. 1 0 .. 1
![Page 15: UML : DIAGRAMME DE CLASSES](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56816498550346895dd66f0f/html5/thumbnails/15.jpg)
UML : DIAGRAMME DE CLASSES
CLASSES PERSISTANTES :
• DEFINITION :Une classe est persistante quand elle perdure dans le temps
COMMANDE
Id CommandeLivrée O/Netc...
LISTE DESCOMMANDES
A LIVRER inclure
0..* 0..1
Classe persistante Classe non persistante
![Page 16: UML : DIAGRAMME DE CLASSES](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56816498550346895dd66f0f/html5/thumbnails/16.jpg)
UML : DIAGRAMME DE CLASSES
CONCEPTS AVANCES…
![Page 17: UML : DIAGRAMME DE CLASSES](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56816498550346895dd66f0f/html5/thumbnails/17.jpg)
UML : DIAGRAMME DE CLASSES
AGREGATION
• DEFINITION :Forme d’association qui spécifie qui spécifie la relation entre un ensemble ou « composé » et sa partie ou « composant ».
Contrainte D’intégrité Fonctionnelle FAIBLE
Agrégation
composécomposant 0 .. 1
![Page 18: UML : DIAGRAMME DE CLASSES](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56816498550346895dd66f0f/html5/thumbnails/18.jpg)
UML : DIAGRAMME DE CLASSES
AGREGATION• La partie (composant) peut exister sans l’agrégat (composé)• Si le composé (agrégat) disparaît, le composant (partie) peut continuer d’exister
4..4 1..1 1..1 1..1
VOITURE
Roue Chassis Moteur Carrosserie
![Page 19: UML : DIAGRAMME DE CLASSES](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56816498550346895dd66f0f/html5/thumbnails/19.jpg)
UML : DIAGRAMME DE CLASSES
COMPOSITION
• DEFINITION :Forme d’agrégation quand l’ensemble ou « composé » est responsable de la création et de la destruction de ses parties.Le Composant n’existe que dans l’association au composé.
Contrainte D’intégrité Fonctionnelle FORTE
Composition
composécomposantChambre d’hôtel Hôtel
1 .. 1
![Page 20: UML : DIAGRAMME DE CLASSES](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56816498550346895dd66f0f/html5/thumbnails/20.jpg)
UML : DIAGRAMME DE CLASSES
COMPOSITION• La partie (composant) n’existe pas sans l’agrégat (composé)• Si le composé (agrégat) disparaît le composant (partie) disparait aussi
1..1 1..* 1..*
SOCIETE
SIEGE AGENCE USINE
![Page 21: UML : DIAGRAMME DE CLASSES](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56816498550346895dd66f0f/html5/thumbnails/21.jpg)
UML : DIAGRAMME DE CLASSES
MULTIPLICITES DES AGREGATIONS ET COMPOSITIONS:•Une agrégation peut avoir N maxi du côté de la classe agrégat
•car l’élément agrégeant peur servir (en même temps ou successivement) à plusieurs agrégats
•Une composition ne peut avoir que 1..1 du côté de la classe composée•car le composant, ne pouvant exister indépendamment du composé, est obligatoirement lié à un seul
VOITURE MOTEUR1..1
O..N
Un moteur peut appartenir à plusieurs voitures (mais
à une seule voiture en même temps)
SOCIETE1..N
1..1
ETABLISSEMENT
![Page 22: UML : DIAGRAMME DE CLASSES](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56816498550346895dd66f0f/html5/thumbnails/22.jpg)
UML : DIAGRAMME DE CLASSES
LA CLASSIFICATION :• 2 Approches :
• La généralisation• La spécialisation
SUPER CLASSE
SOUS CLASSE
Classe plus générale
Classe plus détaillée
spécialisationgé
néralisati
on
![Page 23: UML : DIAGRAMME DE CLASSES](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56816498550346895dd66f0f/html5/thumbnails/23.jpg)
UML : DIAGRAMME DE CLASSES
GENERALISATION:
• Factoriser les éléments communs (attributs, opérations, contraintes) d’un ensemble de classes dans une classe plus générale appelée Super-Classe (ou classe mère).
• Tous les attributs qui se trouvent dans la Super-Classe sont vrais dans toutes les sous-classes.
OISEAU
MOINEAUMESANGE
PlumeBecVoler
![Page 24: UML : DIAGRAMME DE CLASSES](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56816498550346895dd66f0f/html5/thumbnails/24.jpg)
UML : DIAGRAMME DE CLASSES
HERITAGE MULTIPLE:
TAPIS
VEHICULE
AERIENTERRESTREMARIN
TAPIS VOLANT
![Page 25: UML : DIAGRAMME DE CLASSES](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56816498550346895dd66f0f/html5/thumbnails/25.jpg)
UML : DIAGRAMME DE CLASSES
CONTRAINTES DE GENERALISATION:• Une classe peut être spécialisée selon plusieurs critères.• Certaines contraintes peuvent être posées sur les relation de généralisations.• Par défaut, la généralisation symbolise une décomposition exclusive.
VEHICULE
AERIENTERRESTREMARINA MOTEUR A VOILE
motorisation milieu
![Page 26: UML : DIAGRAMME DE CLASSES](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56816498550346895dd66f0f/html5/thumbnails/26.jpg)
UML : DIAGRAMME DE CLASSES
CONTRAINTES DE GENERALISATION :•{ INCOMPLET DISJOINT} ( = {EXCLUSION} )
• Un champignon peut être :Soit un agaricusSoit un BoletusOu Aucun des deux.
CHAMPIGNON
BoletusAgaricus
Pied Bleu Bolet de Loup
{exclusion}
![Page 27: UML : DIAGRAMME DE CLASSES](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56816498550346895dd66f0f/html5/thumbnails/27.jpg)
UML : DIAGRAMME DE CLASSES
CONTRAINTES DE GENERALISATION :•{ COMPLET DISJOINT} ( = {PARTITION} )
• Une personne est : Soit Mineure Soit majeureMais pas les deux.
PERSONNE
MAJEURMINEUR
{partition}
![Page 28: UML : DIAGRAMME DE CLASSES](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56816498550346895dd66f0f/html5/thumbnails/28.jpg)
UML : DIAGRAMME DE CLASSES
CONTRAINTES DE GENERALISATION:•{ COMPLET RECOUVREMENT} ( = {TOTALITE} )
• Un Musicien est obligatoirement : Soit un compositeur Soit un interprète Soit les deux.
MUSICIEN
InterprèteCompositeur
{Totalité}
![Page 29: UML : DIAGRAMME DE CLASSES](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56816498550346895dd66f0f/html5/thumbnails/29.jpg)
UML : DIAGRAMME DE CLASSES
CONTRAINTES D’ASSOCIATIONS:•{ INCOMPLET RECOUVREMENT} ( = {AUCUNE CONTRAINTE} )
• Une Société peut être :ClientFournisseurOu autre chose…
Société
FournisseurClient
{aucune contrainte}
![Page 30: UML : DIAGRAMME DE CLASSES](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56816498550346895dd66f0f/html5/thumbnails/30.jpg)
UML : DIAGRAMME DE CLASSES
POLYMORPHISME• Une opération est polymorphe lorsque :
• Elle est appelée sous forme générique au niveau de la Super-Classe• Elle est spécifiée au niveau de chaque Sous-Classe
Forme
CarréCercle
surface
CalculerSurface()
RPi
Cote
CalculerSurface(){Sf = pi * R * R;}
CalculerSurface(){Sf = cote*cote;}
![Page 31: UML : DIAGRAMME DE CLASSES](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56816498550346895dd66f0f/html5/thumbnails/31.jpg)
UML : DIAGRAMME DE CLASSES
CONSEILS Généralisation - spécialisation:
• Ne spécialiser que si cela apporte un gain.• Ne spécialiser que sur un seul niveau• Par défaut, la généralisation symbolise une décomposition exclusive.
![Page 32: UML : DIAGRAMME DE CLASSES](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56816498550346895dd66f0f/html5/thumbnails/32.jpg)
UML : DIAGRAMME DE CLASSES
CLASSES ABSTRAITES :
• Ne peut être instanciée• On instancie une sous-classe.• Indiquée en italique de manière générale.
![Page 33: UML : DIAGRAMME DE CLASSES](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56816498550346895dd66f0f/html5/thumbnails/33.jpg)
UML : DIAGRAMME DE CLASSES
CLASSES D’INTERFACE:• Décrit le comportement externe visible d’une classe, d’un objet ou d’une autre entité.
Client
<<Interface>> Vendeur
Créer()Modifier()Consulter()
Consulter()
<<Interface>> Secrétaire
1
1
1
1Public Créer()Public Modifier()Public Consulter()
Public Créer()Public Modifier()Public Consulter()
Client Vendeur
Secrétaire
![Page 34: UML : DIAGRAMME DE CLASSES](https://reader035.vdocuments.pub/reader035/viewer/2022081419/56816498550346895dd66f0f/html5/thumbnails/34.jpg)
UML : DIAGRAMME DE CLASSES
EXERCICES