Class diagrams Class diagram

Transcription

Class diagrams Class diagram
UML : Unified Modeling Language
•
•
•
•
•
Use cases
Class Diagram
Interaction Diagrams
State Diagrams
Activity Diagrams
• based on Frank Maurer lecture, Univ. of Calgary
(http://sern.ucalgary.ca/Courses/CPSC/333/W99/CS333.html)
• Recommended: UML distilled… (Addison Wesley)
UML-Class Diagram
[email protected]
1
Class diagrams
• Overview
• Class diagram essentials
• Generalization
UML-Class Diagram
[email protected]
2
Class diagram
• Central for OO modeling
• Shows static structure of the system
– Types of objects
– Relationships
• Association
• Subtypes
UML-Class Diagram
3
[email protected]
Perspectives
• Conceptual
– Shows concepts of the domain
– Independent of implementation
• Specification
– Interfaces of software (types)
– Often best perspective
• Implementation
– Structure of the implementation
– Most often used
UML-Class Diagram
[email protected]
4
Class
• Set of objects
• Defines
– name
– attributes
– operations
Task
startDate
endDate
setStartDate (d : Date = default)
setEndDate (d : Date = default)
getDuration () : Date
UML-Class Diagram
[email protected]
5
Class versus type
• OO type
= protocol understood by an object
= set of methods that are implemented
• Class =
implementation oriented construct
– implements one or more types
UML-Class Diagram
6
[email protected]
Association
• Relationship between instances of classes
A student is registered for a course
A professor is teaching the course
UML-Class Diagram
[email protected]
7
Class diagram example
Actuator
startUp( )
shutDown( )
Light
Heater
Cooler
Temperature
1
1
off( )
on( )
*
1
1
1
Environmental Controller
8
Define_climate( )
UML-Class) Diagram
Terminate_climate(
SystemLog
Display( )
[email protected]
RecordEvent(
)
Rules of thumb
• One class can be part of several diagrams
• Diagrams shall illustrate specific aspects
– Not too many classes
– Not too many associations
– Hide irrelevant attributes/operations
• Several iterations needed to create
diagram
UML-Class Diagram
9
[email protected]
Class diagrams
• Overview
• Class diagram essentials
• Generalization
UML-Class Diagram
[email protected]
10
Association
• Relationship between classes
Order
dateReceived
isPrepaid
number :
String
price : Money
Customer
name
address
hasCustomer
1
*
creditRating( )
dispatch( )
• Order comes from one customer
Customer may make several orders
UML-Class Diagram
[email protected]
11
Naming associations
• Avoid meaningless names
– associated_with
– has
– is_related_to
• Name is often a verb phrase
– has_part
– is_contained_in
UML-Class Diagram
12
[email protected]
Roles
Order
dateReceived
isPrepaid
number :
String
price : Money
dispatch( )
1
• Association has two roles
• Role is a direction on the association
• Role
– Explicitly labeled
– Implicitly named after the target class
line item
*
OrderLine
quantity
price
isSatisfied
UML-Class Diagram
[email protected]
13
Role names
• Role = identifies one end of an association
Company
*
Works for
Name
Address
employer
employee
Person
Name
Insurance no.
Address
• Role name is obligatory for associations
between objects of the same class
Manager
Person
Name
Insurance no.
Address
*
Supervises
UML-Class Diagram
Subordonate
[email protected]
14
Multiplicity
• Indicates how many object can
participate in the relationship
Order
dateReceived
isPrepaid
number :
String
price : Money
Customer
name
address
*
1
creditRating( )
dispatch( )
UML-Class Diagram
15
[email protected]
Multiplicity (2)
•
•
•
•
•
•
* = 0..infinity
1: 1
1 .. *
0..1
1..100
2,4,5
UML-Class Diagram
[email protected]
16
Specification perspective
• Association represents responsibilities
Order
date
Received
isPrepaid
number :
String
price : Money
Customer
name
address
*
1
creditRating( )
Method in Customer returning Orders
Method in Order that returns the
Customer that made the order
UML-Class Diagram
[email protected]
17
Navigability
• Arrows indicate navigability
Order
date
Received
isPrepaid
number :
String
price : Money
Customer
name
address
*
1
creditRating( )
• Order has to be able to determine the
Customer
• Customer does not know Orders
• Bi-directional association: Navigability
in both directions (inverse roles)
UML-Class Diagram
18
[email protected]
Summary: Basic notation for
associations
Association name
Class A
Class B
role_A
role_B
Contains
Part
Order
made_up_of
UML-Class Diagram
included_in
[email protected]
19
Naming conventions
Order
dateReceived
isPrepaid
number :
String
price : Money
• Naming conventions allow often to infer
the names of messages from the diagram
dispatch( )
1
class Order {
public Enumeration orderLines();
public Customer customer();
}
line item
*
OrderLine
quantity
price
isSatisfied
UML-Class Diagram
[email protected]
20
Contents
•
•
•
•
•
•
Attributes and operations
Aggregation
Inheritance
Interfaces and abstract classes
Advanced association concepts
When and how
UML-Class Diagram
21
[email protected]
Attributes
Customer
name
address
creditRating
• Conceptual: Indicates that
customer have names
• Specification: Customer can tell
you his/her name and set it
• Implementation: An instance
variable is available
• UML syntax:
<attribute name>: <Data type>
UML-Class Diagram
[email protected]
22
Difference between
attribute and association
• Conceptual perspective
– not much of a difference!
• Specification/implementation perspective
– Attribute stores values NOT references
• no sharing of attribute values between instances!
• Often: Stores simple objects
– Numbers, Strings, Dates, Money objects
UML-Class Diagram
[email protected]
23
Operations
• Processes that can be carried out on instances
• Correspond to messages of the class
• Conceptual perspective
– principal responsibilities
• Specification perspective
– public messages = interface of the class
• Normally: don’t show operations that
manipulate attributes
UML-Class Diagram
24
[email protected]
UML syntax for operations
<visibility> <name> (<parameter list>) : <return-typeexpression>
+ assignAgent (a : Agent) : Boolean
– visibility: public (+), protected (#), private (-)
• Interpretation is language dependent
• Not needed on conceptual level
– name: string
– parameter list: arguments (syntax as in attributes)
– return-type-expression: language-dependent specification
UML-Class Diagram
[email protected]
25
Types of operations
• Query = returns some value without
modifying the class’ internal state
• Modifier = changes the internal state
• Queries can be executed in any order
• Getting & setting messages
– getting: query
– setting: modifier
UML-Class Diagram
[email protected]
26
Contents
•
•
•
•
•
•
Attributes and operations
Inheritance
Aggregation
Interfaces and abstract classes
Advanced association concepts
When and how
UML-Class Diagram
27
[email protected]
Subclassing
• Class inherits features from (more than) one
superclass
vehicle
land vehicle
car
water vehicle
amphibian
vehicle
UML-Class Diagram
ship
[email protected]
28
Subclassing
• Attributes & operations of an ancestor class are
inherited to the subclass
• Extension: adding of new attributes or
operations
• Restriction: additional restrictions on ancestor
attributes
UML-Class Diagram
[email protected]
29
Perspectives
• Conceptual: Subset relationship
• Specification: Subtype conforms to
supertype interface
• Implementation: Implementation
inheritance, subclassing
UML-Class Diagram
30
[email protected]
Contents
•
•
•
•
•
•
Attributes and operations
Inheritance
Aggregation
Interfaces and abstract classes
Advanced association concepts
When and how
UML-Class Diagram
[email protected]
31
Aggregation
• Special form of association
• Components are parts of aggregated object
– Car has an engine and wheels as its part
• Typical example:
– parts explosion
– organizational structure of a company
UML-Class Diagram
[email protected]
32
Notation for aggregation
Class A
Class B
UML-Class Diagram
33
Class C
[email protected]
Example: Aggregation
0 ..*
Company
0 ..*
Unit
Department
0 ..*
Group
works for
Person
UML-Class Diagram
[email protected]
34
Aggregation and composition
• Composition
Order
Aggregation
*
1
Composition
1
– Components belong only to
one whole
– Parts live and die with the
whole
*
Customer
LineItem
Adress
UML-Class Diagram
• cascading delete
• also needed for 1..1
associations
[email protected]
35
Aggregation association
• Transitive
• Antisymmetric: Object may not be
directly or indirectly part of itself
UML-Class Diagram
36
[email protected]
Recursion
• Directed path of aggregation associations
from a class to itself
• Variable aggregation: finite number of
levels, number of parts variable
(example: company)
UML-Class Diagram
[email protected]
37
Example: recursive aggregation
Class diagram:
Object diagram:
a: Container
Item
c: Container
b: Icon
Icon
Container
d: Icon
UML-Class Diagram
e: Icon
[email protected]
38
Example: Recursive aggregation
Program
*
Class
Inner class
*
UML-Class Diagram
39
[email protected]
Rules for using aggregation
• Distinction between association and
aggregation often rather matter of taste than
difference in semantics
• Aggregation IS association
• Aggregate is inherently sum of its parts
• Chains of aggregate links may not form cycles
• Composition is appropriate when each part is
owned by one object, part has not have an
independent life from its owner
UML-Class Diagram
[email protected]
40
Chaining of operations
• Chaining: Applying an operation to a net
of objects
• Often for: copy, save, redo, delete, print
Person
Document
copy
Paragraph
copy
Character
owns
copy
UML-Class Diagram
copy
copy
[email protected]
41
Delegation & aggregation
vehicle
vehicle
land vehicle
water vehicle
0..1
LandFeature
car
amphibian
vehicle
WaterFeature
ship
VehicleFeature
UML-Class Diagram
42
[email protected]
Most important feature &
aggregation
vehicle
vehicle
land vehicle
land vehicle
big vehicle
train
car
car
train
ship
Size
UML-Class Diagram
[email protected]
43
Generalization based on different
dimensions
vehicle
land vehicle
car
small car
big car
……..
train
small train
UML-Class Diagram
big train
[email protected]
44
Contents
•
•
•
•
•
•
Attributes and operations
Inheritance
Aggregation
Types, interfaces and abstract classes
Advanced association concepts
When and how
UML-Class Diagram
45
[email protected]
OO types
• Stereotype <<type>> specifies
– domain of objects
– operations (not their implementation) applicable to the objects of
this type
• Stereotype
<<implementation class>>
physical data structures and
methods of an object
<<type>>
Collection
<<implementation class>>
HashTableSet
<<type>>
Set
element s : HashTable
addElement(Object)
removeElement(Object)
testElement(Object) : Boolean
UML-Class Diagram
addElement (Object)
removeElement(Object)
tes tElement(Object) : Boolean
setTableSize(Integer)
[email protected]
46
Types and Roles
• interfaces that belong to a class represent
different roles
• You can explicitly state the role a class
presents to another class:
<<interface>>
Employee
Person
getEmploymentHistory()
getCompensation()
getBenefits()
UML-Class Diagram
e: Employee Company
1..*
*
[email protected]
47
Static and dynamic types
• Static types: the type of an object doesn’t
change over time, e.g. classes
• Dynamic types: object can gain and lose
types during lifetime
• Example: Candidate, Employee, Retiree
UML-Class Diagram
48
[email protected]
Abstract class
•
•
•
•
has no instances
organizes attributes & operations
often: facilitates code reuse
abstract operation: implementation in
concrete subclasses
• can contain concrete implementations
UML-Class Diagram
[email protected]
49
Abstract class in UML
• Name in italic and/or {abstract} constraint
Windows Window
toFront()
toBack()
Window
X11 Window
{abstract}
Text
Editor
toFront()
toBack()
toFront()
toBack()
Mac Window
Dependency
toFront()
toBack()
UML-Class Diagram
[email protected]
50
Interfaces in UML (1)
• Stereotype <<interface>>
• (Java implementation oriented)
<<interface>>
InputStream
DataInput
OrderReader
{abstract}
Generalization
Realization (or refinment)
DataInputStream
UML-Class Diagram
51
Dependency
[email protected]
Parameterized classes
• Parameterized class = template
• Often used for collections in typed languages
• Not needed in conceptual modeling
– Collections are hidden in multiplicity
T
Set
insert (newArg : T = default)
remove (arg : T = default)
UML-Class Diagram
[email protected]
52
Bound element
• Using a parameterized class
T
Set
Template Class
insert(T)
remove(T)
Set <Employees>
Refinement
Bound Element
UML-Class Diagram
<<bind>>
<Employee>
EmployeeSet
[email protected]
53
Contents
•
•
•
•
•
•
Attributes and operations
Inheritance
Aggregation
Interfaces and abstract classes
Advanced association concepts
When and how
UML-Class Diagram
54
[email protected]
Binding for
Parameter
Constraints
• Basic constructs specify important
constraints
– but cannot capture everything
• Additional constraints: in braces { }
{immutable}
{read only}
UML-Class Diagram
[email protected]
55
Example
Chair-of
*
1
Person
Committee
{subset}
*
*
Member-of
UML-Class Diagram
[email protected]
56
Collections for multi-valued roles
• Role with multiplicity > 1, basically, the
semantics of “Set”
• no target object appears more than once
• not ordered
• Add constraint to change that
{ordered}
{ordered bag}
{dag}
{bag}
{hierarchy}
{ordered}
Screen
Window
Visible on
UML-Class Diagram
57
[email protected]
Association classes
• Useful if
– attributes don’t belong to any one class but
to the association
Person
Company
employer
*
0..*
Employment
Period : dateRange
UML-Class Diagram
[email protected]
58
Remodeling: association classes
*
/employer
*
Person
Company
Employment
1
0..*
Period :dateRange
UML-Class Diagram
*
1
[email protected]
59
Qualified associations (1)
o1
o2
o3
o4
44
56
87
99
• UML equivalent for Hashtable
Task
name : String
ToDoList
0..1
– Within a ToDoList, you mustn’t have two
tasks with the same name
class ToDoList {
public Task getTask(String name);
public void addTask(String name, Task aTask);
…}
– Multiplicity *: Multiple task with one name
UML-Class Diagram
60
[email protected]
Qualified association (2)
• Improves semantic accuracy
• Makes navigation paths understandable
Stock
exchange
Stock
exchange
StockID
not
qualified
noted
*
qualified
noted
Company
StockID
Company
UML-Class Diagram
[email protected]
61
Qualified association (3)
• Qualification splits a set of objects in
disjunctive parts
Organization
Person
Company Function
ABC Inc.
ABC Inc.
ABC Inc.
ABC Inc.
ABC Inc.
XYZ Inc.
President
Vice President Finances
Member of board
Member of board
Member of board
President
UML-Class Diagram
Roger Rabbit
Joe Savemoney
John Walker
Susi Sanssouci
Karl Eichbaum
Donald Duck
[email protected]
62
Derived associations and
attributes (1)
• Calculated based on other attributes and
associations
• Specification: Shows constraint not what is
stored and what is calculated
UML-Class Diagram
63
[email protected]
Derived associations and
attributes (2)
{balance = sum of amounts
of entries}
Components
{hierarchy}
*
Account
/entries
*
/balance:Money
Derived Attribute
Entry
amount:Money
Derived Role
Summary
0..1 Account
Detail
Account
Entries role is derived using
components.entries
1
Note
UML-Class Diagram
[email protected]
64
Derived associations and
attributes (2)
{balance = sum of amounts
of entries}
Components
{hierarchy}
*
Entry
Account
amount:Money
Derived Attribute
Summary
0..1 Account
Detail
Account
Entries role is derived using
components.entries
UML-Class Diagram
1
Note
[email protected]
65
Contents
•
•
•
•
•
•
Attributes and operations
Inheritance
Aggregation
Interfaces and abstract classes
Advanced association concepts
When and how
UML-Class Diagram
66
[email protected]
When to use class diagrams
• Class diagrams are the backbone of OO
development approaches
• Don’t use all the notations
– start with simple stuff
• Take the perspective into account
– not too many details in analysis
– specification often better than implementation
• Concentrate on key areas
– better few up-to-date diagrams than many obsolete
models
UML-Class Diagram
[email protected]
67
Creating a class diagram
• Start simple
– major classes & obvious associations
• Then add
– Attributes
– Multiplicity
– Operations
UML-Class Diagram
[email protected]
68
Rules of thumb
• One class can be part of several diagrams
• Diagrams shall illustrate specific aspects
– Not too many classes
– Not too many associations
– Hide irrelevant attributes/operations
• Several iterations needed to create
diagram
UML-Class Diagram
69
[email protected]
Avoid “Heavy” classes
• Controller does everything
• Other classes: Data encapsulation only
A
D
HeavyControler
doIt( )
B
C
UML-Class Diagram
[email protected]
70
Gestion d’une bibliothèque.
• On veut développer un système pour gérer les prêts dans une
bibliothèque. Une première analyse des besoins fait ressortir les
faits suivants :
•
une bibliothèque prête des livres ou des magazines à des emprunteurs,
les livres, les magazines et les emprunteurs sont enregistrés dans le système
une bibliothèque gère l’achat de nouveaux titres. Les titres sont en général achetés
en plusieurs exemplaires
les livres et magazines sont retirés des prêts lorsqu’ils ne sont plus à jour ou abimés
les client interagissent avec les bibliothécaires qui gèrent le système
un emprunteur peut réserver un titre qui n’est pas disponible. Lorsqu’il y a un
retour, un emprunteur en attente est averti
une réservation est annulée lorsqu’un emprunteur récupère le livre correspondant ou
à sa demande explicite
le bibliothécaire doit pouvoir gérer les prêts, les emprunteurs, les réservations …
….
-
•
•
•
•
•
•
•
•
UML-Class Diagram
[email protected]
71
Action
#argument[1..1] : int
+appliquerAction : int
+estactionvalide : bool
+donnerArgument : int
AppliquerEchange
DemanderEchange
VendreMaison
PayerLoyer
+appliquerAction : int
+appliquerAction : int
+appliquerAction : int
+appliquerAction : int
+estactionvalide : bool
+estactionvalide : bool
+estactionvalide : bool
+estactionvalide : bool
RacheterHypotheque
Hypothequer
Banqueroute
AchatMaison
jeu
-situation[1..1] : int
+appliquerAction : int
+appliquerAction : int
+appliquerAction : int
+appliquerAction : int
+estactionvalide : bool
+estactionvalide : bool
+estactionvalide : bool
+estactionvalide : bool
Avancer
TourEnPrison
Rien
-etat[1..1] : int
Planjeu
-parcGratuit[1..1] : int
+nbCase:int
-JoueurCourant[1..1] : int
+appliquerAction : int
+appliquerAction : int
+appliquerAction : int
+estactionvalide : bool
+estactionvalide : bool
+estactionvalide : bool
Suivant
Perdre
Recevoir
Constantes :
Situation
Aucune :
i t
Prison
:
i t
Dialogue
:
i t
Achat
:
i t
-nbCase[1..1] : int
-nbjoeur[1..1] : int
PayerPrison
+appliquerAction : int
+estactionvalide : bool
Reculer
Constantes : Etat
DebutTour :
i t
LancerDes
:
i t
Avancer
:
i t
Actioncase
:
i t
Suivant
:
i t
Banqueroute
Demanderchange
i t
:
i t
Echangeaccepte
:
i t
Perte
:
i t
Casecommunauté
+numero:int
+situation : int
Case
+etat : int
#position[1..1] : int
+Joueurcourant : int
#nom[1..1] : string
+nbjoueur : int
AllerPrison
Casechance
+Tirerchance : chance
+appliquerAction : int
+appliquerAction : int
+estactionvalide : bool
+estactionvalide : bool
Achat
Vente
+appliquerAction : int
+appliquerAction : int
+Tirercommunaute : communaute
+estactionvalide : bool
+estactionvalide : bool
+numeroJoueurCourant:int
PrendreParcGratuit
Prison
parc_gratuit
+caution[1..1] : int
+nbToursPrison[1..1] : int
+appliquerAction : int
+appliquerAction : int
+appliquerAction : int
+estactionvalide : bool
+estactionvalide : bool
+estactionvalide : bool
+estactionvalide : bool
Aller
1..1
AllerEnPrison
+appliquerAction : int
CaseDépart
Propriété
PayerParcGratuit
Accepter
Des
+appliquerAction : int
+appliquerAction : int
+estactionvalide : bool
+estactionvalide : bool
+estactionvalide : bool
+lancer : void
+donnervaleur : int
#Possede famille[1..1] : bool
1..6
#famille[1..1] : int
#Prix[1..1] : int
Joueur
+hypothequer : void
-position[1..1] : int
+estHypothequer : bool
-numero[1..1] : int
+acheter : void
-somme_initiale[1..1] : int
carte
+vendre : void
-compte[1..1] : int
+int numéro[1..1] :
+famille : int
-nom[1..1] : string
+joueur propriétaire[1..1] :
+prix : int
-toursEnPrison[1..1] : int
+prixHypothequer : int
-actif[1..1] : bool
+racheterhypotheque : void
+estActif : bool
+actualiserproprietaire : void
+jouer : action
Communauté
Chance
+montant[1..1] : int
#proprietaire[1..1] : int
#hypotheque[1..1] : bool
+valeur[1..1] : int
+Operation2
+possedeFamille : bool
+avoirPosition : int
+tourEnPrison : int
+souscompte : void
+nbMaisons[1..1] : int
+calculCcompte : int
+loyer[1..1] : int
+avoirNom : string
+avoirnumero : int
Compagnie
Terrain
+adcompte : void
+loyer[1..1] : int
+calculLoyer : int
+vendreMaison : void
+estdestructible : bool
+calculnbmaison : int
Gare
+loyer[1..1] : int
+calculLoyer : int
+calculprixmaison : int
+estconstuctible : bool
+acheterMaison : void
+calculLoyer : int
UML-Class Diagram
72
[email protected]
D és
M o n o p o ly
D é [1 ..1 ] : i n t
N o m b r e _ C a s e s [1 ..1 ] : i n t
N o u ve l l e _ P a r ti e ( )
L a n c e r( )
1 ..1
Q u i tte r _ P a r ti e ( )
1 ..1
1 ..1
Jou eurs
N o m [1 ..1 ] : s tr i n g
A r g e n t[1 ..1 ] : i n t
2 ..6
G a re s
l i b é r a ti o n [1 ..1 ] : b o o l
P r i s o n [1 ..1 ] : b o o l
N o m [1 ..1 ] : s tr i n g
P r i x[1 ..4 ] : i n t
P r o p r i é té s
0 ..*
ve n d r e _ p r o p r i e te ( )
h yp o th e q u e r _ p r o p r i e te ( )
r e s i l i e r _ p r o p r i e te ( )
P a ye r _ l o ye r ( )
ve n d u [1 ..1 ] : b o o l
h yp o th e q u e r [1 ..1 ] : b o o l
1 ..1
a c h a t_ p r o p r i e te ( )
C o m p a g n i e s d e s e a u x e t é l e c tr i c i té
1 ..1
1 ..1
1 ..1
0 ..*
N o m [1 ..1 ] : s tr i n g
P r i x[1 ..1 ] : i n t
P io n
C a r te s
D é p la c e r( )
N o m [1 ..1 ] : s tr i n g
L i r e _ c a r te ( )
Im p o ts [1 ..1 ] : i n t
P a ye r _ l o ye r ( )
1 ..*
P la te a u
Te rra in s
a r g e n t[1 ..1 ] : i n t
p r o p r i e ta i r e [1 ..1 ] : i n t
N o m _ p a r ti e [1 ..1 ] : s tr i n g
N o m [1 ..1 ] : i n t
N o m b r e _ j o u e u r s [1 ..1 ] :
T e m p s _ p r é vu [1 ..1 ] :
C o u l e u r [1 ..1 ] : s tr i n g
P r i x_ l o ye r _ à _ p a ye r [1 ..1 ] : i n t
A ffi c h e r ( )
P r i x_ l o ye r _ a ve c _ m a i s o n [1 ..1 ] : i n t
1 ..1
P r i x_ l o ye r _ a ve c _ h o te l [1 ..1 ] : i n t
P r i x_ b a ti m e n t[1 ..1 ] : i n t
C as es
N o m b r e _ m a i s o n [1 ..1 ] : i n t
N o m b r e _ h o te l [1 ..1 ] : i n t
P a ye r _ l o ye r ( )
N o m [1 ..1 ] : s tr i n g
A c h a t_ b a ti m e n t( )
ti r e r u n e
c a r te
C a i s s e d e c o m m u n a u té
1 ..1
C a rte _ C d C
V e n te _ b a ti m e n t( )
T e xte [1 ..1 ] : s tr i n g
M o n ta n t_ c a r te [1 ..1 ] : i n t
C a s e _ p ris o n
T i r e r _ u n e _ c a r te ( )
1 ..1
Alle r_ e n _ p ris o n ( )
C a rte _ c h a n c e
C h an ce
1 ..1
1 ..1
T e xte [1 ..1 ] : s tr i n g
C a s e p a r k i n g g r a tu i t
V a l e u r [1 ..1 ] : i n t
T i r e r _ u n e _ c a r te ( )
a r g e n t a u c e n tr e [1 ..1 ] : i n t
D o n n e r _ a r g e n t( )
A va n c e r [1 ..1 ] : s tr i n g
ti r e r u n e c a r te
T a xe s
C a s e d e p a rt
M o n ta n t[1 ..1 ] : i n t
R é c e p ti o n _ s a l a i r e [1 ..1 ] : i n t
P a ye r ( )
D o n n e r_ s a la ir e ( )
UML-Class Diagram
73
[email protected]
C a s e _ a lle r_ e n _ p ris o n
Jeu
collection de joueurs[1..1] :
Dés
Total_dés[1..1] : int
double[1..1] : bool
total.obtenir( )
double.vérif( )
1..1
en fait 2..2
collection de cases[1..1] :
C a rte C h an ce /C a i s s e C o m
collection de cartes[1..1] :
Intitulé[1..1] : text
nom_joueur.obtenir( )
montant_prime[1..1] : int
nom_propriétaire.obtenir( )
intitulé_case.obtenir( )
montant_pénalité[1..1] : int
intitulé_carte.obtenir( )
passage_départ.vérif( )
montant_prime.obtenir( )
joueur.supprimer( )
montant_pénalité.obtenir( )
lancer
1..1
C h an ce / C ai s s e C om .
B anq ui er
Jo ue ur
Type[1..1] : text
Nb_maisons_reste[1..1] : int
Nom[1..1] : string
Nb_hôtels_reste[1..1] : int
Solde[1..1] : int
Nb_gares[1..1] : int
1..*
Nb_compagnies[1..1] : int
transactions
C as e
nb_maisons_reste.vérif( )
nb_hôtels_reste.vérif( )
intitulé.obtenir( )
rembourse_maisons( )
quartier=tableau[1..1] : bool
1..1
Nb_doubles[1..1] : int
D é part
Intitulé[1..1] : text
Parc g ratu i t
prête_argent( )
Montant[1..1] : int
Prison[1..1] : bool
montant.obtenir( )
Nb_tours_prison[1..1] : int
montant.ajouter( )
Carte_libération[1..1] : bool
montant.retirer( )
Pri s on
Pro pri é té s
hypothèque
1..1
montant.ajouter( )
quartier[couleur].vérif( )
0..*
Simple_visite[1..1] : bool
Disponible[1..1] : bool
Hypothèque[1..1] : bool
solde.vérif( )
achète/vend
1..1
0..*
carte_libération.vérif( )
Nom_propriétaire[1..1] : string
Px_propriété[1..1] : int
Im pô ts / Taxe de l uxe
Type[1..1] : text
dispo.vérif( )
Montant_impôts[1..1] : int
nom_propriétaire.obtenir( )
px_loyer.obtenir( )
Montant_taxe[1..1] : int
montant_à_payer.obtenir( )
px_propriété.obtenir( )
Al l e z en pri s on
Rue
Gare
C o m p ag ni e s
Loyer_terrain_nu[1..1] : int
Px_si_1[1..1] : int
Coef_si_1[1..1] : int
Loyer_1_maison[1..1] : int
Px_si_2[1..1] : int
Coef_si_2[1..1] : int
Loyer_2_m[1..1] : int
Px_si_3[1..1] : int
Px_si_4[1..1] : int
Loyer_3_m[1..1] : int
Loyer_4_m[1..1] : int
Loyer_1_hôtel[1..1] : int
Px_maison[1..1] : int
Px_hôtel[1..1] : int
Nb_maisons[1..1] : int
Hôtel[1..1] : bool
Couleur[1..1] : int
nb_maisons.vérif( )
px_hôtel.obtenir( )
px_maison.obtenir( )
UML-Class Diagram
[email protected]
couleur.obtenir( )
74
nb_maisons.obtenir( )
d i a gr a m m e d e cl a s s es 0 6 /12 /2 0 01
d i a g_ cl a s s
de p a rt
b a nq u e
1:1
int somme[1..1] :
int compte[1..1] :
int nb_maison[1..1] :
j o ue u r
int nb_hotel[1..1] :
int position[1..1] :
string name[1..1] :
p ar ki n g g r a tui t
1:1
int somme[1..1] :
2:8
int compte[1..1] :
42:42
int numero_joueur[1..1] :
bool prisonnier[1..1] :
1:1
1:1
ca s e
int nb_tour_enprison[1..1] :
0:8
int nb_carte_liberation[1..1] :
m o n o p ol y
2:8
2:8
1:1
int nb_joueurs [1..1] :
terrain propriétés[int couleur][int numero_terrain][1..1] :
bool posséde_s erie_terrains[1..1] :
string nom_partie[1..1] :
int deplacement_vers(int case)
terrains tab_terrains[int numero][1..1] : joue
joueur1:1
joueur_courant[1..1] :
void est_en_prison()
joueur tab_joueurs[int numero][1..1] :
void achat_mais on(terrain nom_rue,int nb_maisons)
int résultat_dé1[1..1] :
void vente_maison(terrain nom_rue,int nb_maisons)
int résultat_dé2[1..1] :
void achat_t(terrain nom_terrain,int prix)
void vente_t(terrain nom_terrain,int prix)
1:1
void lancer_dés()
déplace_vers
1:1
ca i s s e d e co m m u n au té
int position[1..1] :
string nom[1..1] :
ch an ce
int deplacement(int deplacement)
propriétaire
p ri s o n
1:1
possède
int caution[1..1] :
propriété
void ajouter_t(terrain nom_terrain)
te r ra i n s
0:28
void retirer_t(terrain nom_terrain)
int prix[1..1] :
int prix hypothèque[1..1] :
s i m pl e vi s i te
joueur propriétaire[1..1] :
bool libre[1..1] :
...
bool hypothèqué[1..1] :
r ue s
int couleur_série[1..1] :
int nb_terrains_de_la_série[1..1] :
ta xe d e l uxe
int somme [1..1] :
int nb_maisons[1..1] :
g a re
int prix_maison[1..1] :
1:1
int loyer[int nb_maisons][1..1]
:
int couleur_série=-1[1..1] :
int nb_gare[1..1] :
int nb_terrain_meme_couleur[1..1] :
int loyer[int nb_gare][1..1] :
1:1
m a i s o ns
co m p a g ni e s
int couleur_série=-2[1..1] :
i m po ts
int coeff=1[1..1] :
int somme[1..1] :
int coeff=2[1..1] :
1:1
h o te l
ca r te
carte carte_suivante[1..1] :
int muméro_action[1..1] :
joueur propriétaire[1..1] :
string text[1..1] :
carte tirer_carte(joueur j)
void action(carte c)
ca rte cd co m m u na u té
UML-Class Diagram
75
[email protected]
c ar te cha n ce
1 ..1
S ys te m e
Banque
re s e rve [1 ..1 ] : in t
s a la ire [1 ..1 ] : i n t
1 ..1
1 ..1
n b _ ca s e s _ re s t[1 ..1 ] : in t
B AN k[1 ..1 ] : in t
fa ire _ fa illite ( )
g e t_ n b m a is o n ( )
g ive _ s a la i re ( )
1 ..1
1 ..1
g e t_ l ib ( )
g ive re s e rve (jo u e u r) : in t
a tte n te ( )
ch g t_ re s e rve ( )
ch g t_ b a n k ( )
s u p p rim e r_ p o s s e s s io n ( )
g ive s a la i re ( jo u e u r ) : in t
1 ..*
1 ..*
h yp o th e q u e r ( )
p a ye r ( )
1 ..*
Jo ueu r
Po s s e s s io n s
a jo u t_ to ta lm a is o n ( )
a jo u t_ m a i s o n ( )
to ta lm a is o n [1 ..1 ] : i n t
fa illite [1 ..1 ] : b o o l
Attrib u te 7 [1 ..1 ] :
lib e ra tio n [1 ..1 ] : b o o l
to u r_ p ris o n [1 ..1 ] : in t
R U E S (ta b le a u x d e ru e s p a r e x)[1 ..1 ]
d e p la ce m e n t[1 ..1 ] : i n t
a jo u t_ ru e (jo u e u r, ru e )
e ta t[1 ..1 ] : b o o l
a ch e te r (b o o l,ru e ,jo u e u r)
tire lire [1 ..1 ] : in t
g e t_ p o s s e s s e u r ( )
l ie u [1 ..1 ] :
n o m [1 ..1 ] : s trin g
p a ye r_ re s e rve (jo u e u r)
fa ire fa illite ( ) : b o o l
g ive _ re s e rve (j o u e u r)
u tilis e _ lib ( ) : b o o l
ch a n g e m e n t_ e ta t (jo u e u r )
g e t_ c a s e ( jo u e u r, in t)
p o s s e s s io n _ c a ch e e [1 ..1 ] : b o o l
m o d if_ p o s s e s io n ( )
u tilis e _ lib ( )
a jo u tto ta lm a is o n (i n t)
a jo u tru e (ru e )
g e tn b m a is o n ( ): in t
m o d if_ lib ( )
g e t_ p ro p ri o ( )
p a ye r_ b a n k (jo u e u r,in t)
lire ( )
h yp o th e q u e ( ) : b o o l , in t
g e tl ib ( ): b o o l
g e t_ e ta t (j o u e u r)
p a ye rre s e rve (in t)
1 ..1
Rue
g e t_ l ie u (j o u e u r )
a tte n d re ( )
g e tto u r ( ) : in t
p a ye r_ va le u r( jo u e u r,in t)
p rix_ a ch a t[1 ..1 ] : in t
p o s s e s s e u r[1 ..1 ] : b o o l
la n c e le s d é s
p a ye rb a n k (in t)
co u le u r[1 ..1 ] : in t
1 ..1
n b _ m a is o n [1 ..1 ] : in t
1 ..1
g e tca s e (in t):ca s e
d o u b le [1 ..1 ] : b o o l
c h a n g e m e n te ta t ( )
p ro p rie ta ire [1 ..1 ] :
1 ..*
h yp o th e q u e [1 ..1 ] : in t
p rix m a i s o n [1 ..1 ] : in t
1 d e [1 ..1 ] : in t
l a n ce _ d e s ( ):in t,b o o l
2 d e [1 ..1 ] : in t
g e tlie u ( ):c a s e
s o m m e [1 ..1 ] : i n t
a jo u tm a is o n ( in t )
n b d o u b le [1 ..1 ] : in t
1 ..1
ch g t_ p ro p rio ( )
ch g t_ p o s s e s s e u r ( )
Cas e
ch g t_ n b d o u b le ( )
g e t_ n b d o u b le ( ): in t
n u m e ro _ ca s e [1 ..1 ] : in t
g e tp o s s e s s e u r ( ) : b o o l
g e t_ s o m m e (): in t
g e tp ro p rio ( ): jo u e u r
g e t_ d o u b l e (): b o o l
C han ce
76
1 ..1
Dés
g e te ta t ( ): b o o l, in t
p rix_ lo ye r[1 ..1 ] :
le ct_ ca rte [1 ..1 ] : in t
lire _ ca rte () : in t
P ris o n
C a s e d é p a rt
UML-Class
Diagram
s a la ire _ s p e [1 ..1 ] : in t
Im p o t
P a r k i n g g r a tu i t
[email protected]
va le u rd u e [1 ..1 ] : in t
re s e rve [1 ..1 ] : in t