Professional Documents
Culture Documents
Class Diagrams Describe The Types of Objects
Class Diagrams Describe The Types of Objects
3 Class Diagrams
Subject/Topic/Focus:
Summary:
Parameterized Classes
Literature:
Fowler
Rumbaugh
3.3.1
subtypes
a student is a kind of person
Class diagrams also show the attributes and operations of a class and
the constraints that apply to the way objects are connected.
3.3.2
3.3.1
Activity Diagrams
inter-class behavior:
describe control flow
between classes
Class Diagrams
Interaction Diagrams
scenarios:
describe typical interaction
sequences between classes
structuring
intra-class behavior:
describe states and
state transitions
in classes
Package Diagrams
State Diagrams
Class
Classdiagrams
diagramsare
arecentral
centralfor
foranalysis,
analysis,design
designand
andimplementation.
implementation.
Class
Classdiagrams
diagramsare
arethe
therichest
richestnotation
notationininUML.
UML.
OOA&D J.W. Schmidt, F. Matthes, TU Hamburg-Harburg
3.3.3
3.3.4
3.3.2
Customer
Association
Multiplicity
Order:
Order:
We
Wehave
havecustomers
customerswho
whomay
mayorder
orderseveral
severalproducts.
products.
We
distinguish
corporate
customers
from
We distinguish corporate customers frompersonal
personalcustomers,
customers,since
since
corporate
corporatecustomers
customersare
arebilled
billedmonthly
monthlywhereas
whereaspersonal
personalcustomers
customers
need
needto
toprepay
prepaytheir
theirorders
orderswith
withaacredit
creditcard.
card.
We
Wewant
wantour
ourorders
ordersto
tobe
belined
linedup
upproduct
productby
byproduct.
product.
Each
Eachline
lineshould
shouldcontain
containthe
theamount
amountand
andthe
theprice
priceof
ofeach
eachproduct.
product.
OOA&D J.W. Schmidt, F. Matthes, TU Hamburg-Harburg
3.3.5
Customer
Generalization
Corporate
Customer
Personal
Customer
Order:
Order:
We
Wehave
havecustomers
customerswho
whoorder
orderour
ourproducts.
products.
We
Wedistinguish
distinguishcorporate
corporatecustomers
customersfrom
frompersonal
personalcustomers,
customers,since
since
corporate
customers
are
billed
monthly
whereas
personal
corporate customers are billed monthly whereas personalcustomers
customers
need
needto
toprepay
prepaytheir
theirorders
orderswith
withaacredit
creditcard.
card.
We
Wewant
wantour
ourorders
ordersto
tobe
belined
linedup
upproduct
productby
byproduct.
product.
Each
line
should
contain
the
amount
and
the
Each line should contain the amount and theprice
priceof
ofeach
eachproduct.
product.
OOA&D J.W. Schmidt, F. Matthes, TU Hamburg-Harburg
3.3.6
3.3.3
Line item
Order Line
Product
Customer
Corporate
Customer
Personal
Customer
Order:
Order:
We
Wehave
havecustomers
customerswho
whoorder
orderour
ourproducts.
products.
We
distinguish
corporate
customers
We distinguish corporate customersfrom
frompersonal
personalcustomers,
customers,since
since
corporate
corporatecustomers
customersare
arebilled
billedmonthly
monthlywhereas
whereaspersonal
personalcustomers
customers
need
needto
toprepay
prepaytheir
theirorders
orderswith
withaacredit
creditcard.
card.
We
Wewant
wantour
ourorders
ordersto
tobe
belined
linedup
upproduct
productby
byproduct.
product.
Each
Eachline
lineshould
shouldcontain
containthe
theamount
amountand
andthe
theprice
priceof
ofeach
eachproduct.
product.
OOA&D J.W. Schmidt, F. Matthes, TU Hamburg-Harburg
3.3.7
Customer
Attributes
Operations
name
address
creditRating()
dispatch()
close()
Order:
Order:
We
Wehave
havecustomers
customerswho
whoorder
orderour
ourproducts.
products.
We
Wedistinguish
distinguishcorporate
corporatecustomers
customersfrom
frompersonal
personalcustomers,
customers,since
since
corporate
customers
are
billed
monthly
whereas
personal
corporate customers are billed monthly whereas personalcustomers
customers
need
needto
toprepay
prepaytheir
theirorders
orderswith
withaacredit
creditcard.
card.
We
Wewant
wantour
ourorders
ordersto
tobe
belined
linedup
upproduct
productby
byproduct.
product.
Each
line
should
contain
the
amount
and
the
Each line should contain the amount and theprice
priceofofeach
eachproduct.
product.
OOA&D J.W. Schmidt, F. Matthes, TU Hamburg-Harburg
3.3.8
3.3.4
Multiplicity: mandatory
dateReceived *
1
isPrepaid
number:String
Association
price:Money
Generalization
dispatch()
Constraint
close()
Role name
Line item
1 {If Order.customer.creditRating
is poor, then Order.isPrepaid
must be true}
Order Line
quantity:Integer
*
price:Money
isSatisfied:Bool
Attributes
Operations
1
Product
Customer
name
address
creditRating()
Corporate
Customer
Personal
Customer
contactName
creditRating
creditLimit
creditCard#
Multiplicity: optional
*
Remind()
billforMonth(Int)
0..1
Employee
Multiplicity: many-valued
3.3.9
Perspectives
There are three perspectives (views) you can use in drawing class diagrams:
Conceptual
represents the concepts relating to the classes
provides language independence
Specification
represents the software interfaces
hides the implementation
Implementation
shows the real classes used in the programming language
maps directly to the implementation
3.3.10
3.3.5
Attributes
Customer
Customer
Attributes
name
name
address
address
3.3.11
Operations
Customer
Customer
Operation
creditRating()
creditRating()
In the implementation view usually private and protected methods are shown.
The use of UML syntax for operations may vary with the level of detail:
3.3.12
3.3.6
Visibility is
Identifier
is defined by a string.
Parameter-list
Return-type-expression
Property-string
++creditRating(for
creditRating(for: :Year)
Year): :Rating
Rating{abstract}
{abstract}
OOA&D J.W. Schmidt, F. Matthes, TU Hamburg-Harburg
3.3.13
Method
Operation
Class
ClassObject
Object
move(dx,dy)
move(dx,dy)
move(dx,dy)
move(dx,dy)
Class
ClassPoint
Point
move(dx,dy)
move(dx,dy)
aPoint.move(dx,dy)
aPoint.move(dx,dy)
aCircle.move(dx,dy)
aCircle.move(dx,dy)
...
...
anObject.move(dx,dy)
anObject.move(dx,dy)
Class
ClassCircle
Circle
extends
extendsPoint
Point
move(dx,dy)
move(dx,dy)
OOA&D J.W. Schmidt, F. Matthes, TU Hamburg-Harburg
3.3.14
3.3.7
Associations
IBM
Instances
Instancesare
aremarked
marked
by
byunderlining.
underlining.
Mary
Each association has two roles that may be named with a label.
Employer
Person
Employee
Company
Person
Company
3.3.15
Associations: Multiplicities
A customer may
have many orders.
Order
Customer
The
3.3.16
3.3.8
Navigability
Order
Order
Customer
Customer
Navigation direction
3.3.17
Aggregation
Computer
Engine
Car
CPU
1
2..4
Door
Company
1
*
Employee
3.3.18
3.3.9
Composition
Example:
Aggregation
Company
Employee
Composition
Tax Registration
3.3.19
Polygon
1
Aggregation
Composition
{ordered} 3..*
Point
Point
Graphical
GraphicalIcon
Icon
color
color
texture
texture
3.3.10
Association Classes
Example: Persons are employed by companies for a period of time.
Question: Where does the period attribute go?
Association classes allow you to model associations by classes, i.e., to add
attributes, operations and other features to associations.
employee
Person
Person
employer
Company
Company
0..1
Association class
Employment
Employment
period:DateRange
period:DateRange
Note: a person and a company are associated only by one employment period here.
3.3.21
*
Person
Person
0..1
Employment
Employment
1
0..1
period:DateRange
period:DateRange
Company
Company
But: A person may have only one competency level for each skill:
Person
Person
Skill
Skill
Competency
Competency
level
level
OOA&D J.W. Schmidt, F. Matthes, TU Hamburg-Harburg
Association class
3.3.22
3.3.11
Generalization
Generalization captures similarities between several classes in a superclass
Specialization refines and adds differences in subclasses.
Customer
Customer
name
name
address
address
creditRating()
creditRating()
Corporate
Corporate
Customer
Customer
contactName
contactName
creditRating
creditRating
creditLimit
creditLimit
Personal
Personal
Customer
Customer
creditCard#
creditCard#
Remind()
Remind()
billforMonth(Int)
billforMonth(Int)
OOA&D J.W. Schmidt, F. Matthes, TU Hamburg-Harburg
3.3.23
Generalization: Perspectives
3.3.24
3.3.12
Interfaces
Generalization/
Refinement
<<interface>>
<<interface>>
Window
Window
toFront()
toFront()
toBack()
toBack()
Windows
Windows95
95Window
Window
toFront()
toFront()
toBack()
toBack()
Mac
MacOS
OSWindow
Window
toFront()
toFront()
toBack()
toBack()
OOA&D J.W. Schmidt, F. Matthes, TU Hamburg-Harburg
3.3.25
Abstract Classes
Window
Window
{abstract}
{abstract}
Text
Text
Editor
Editor
void move(int dx, int dy)
{
hide();
x = x+dx; y = y+dy;
show();
}
x,x,yy
hide()
hide(){abstract}
{abstract}
show()
show(){abstract}
{abstract}
move(dx,
move(dx,dy)
dy)
Windows
Windows95
95Window
Window
hide()
hide()
show()
show()
Mac
MacOS
OSWindow
Window
hide()
hide()
show()
show()
Implementation
3.3.26
3.3.13
InputStream
{abstract}
OrderReader
DataInput
Generalization
Dependency
Refinement
DataInputStream
OOA&D J.W. Schmidt, F. Matthes, TU Hamburg-Harburg
3.3.27
Lollipop Notation
The interfaces or abstract classes are represented by small circles
(lollipops), coming off the classes that implement them.
DataInput
OrderReader
OrderReader
Interface
DataInputStream
DataInputStream
Dependency
Implementation class
Abstract class
InputStream
3.3.28
3.3.14
InputStream
DataInput
DataInputStream
InputStream
<<interface>>
DataInput
DataInputStream
3.3.29
Issues:
May an object belong to different classes, e.g. Patient and Doctor?
May an object change its class, e.g., from Patient to Doctor?
3.3.30
3.3.15
Multiple Classification
Person
Person
Patient
Patient
Doctor
Doctor
patient
profession
Discriminator
Nurse
Nurse
3.3.31
Patient
Patient
patient
Person
Person
profession
Doctor
Doctor
Multiple inheritance: a class may have many superclasses but for each object
a single class must be defined.
Doctor
Doctor
Person
Person
DoctorAsPatient
DoctorAsPatient
Patient
Patient
3.3.32
3.3.16
Female
Female
Person
Person
Male
Male
Person
Person
profession
sex
Person
Person
Physiotherapist
Physiotherapist
Nurse
Nurse
Surgeon
Surgeon
{complete}
patient
Doctor
Doctor
Patient
Patient
Family
Family
Doctor
Doctor
(Male, Physiotherapist)
(Female, Patient)
OOA&D J.W. Schmidt, F. Matthes, TU Hamburg-Harburg
3.3.33
Dynamic Classification
Example:
A persons profession can change over time. Paul may be a
Physiotherapist and become a Doctor (he could not be both at the
same time!).
profession
<<dynamic>>
Person
Person
PhysioPhysiotherapist
therapist
Nurse
Nurse
Doctor
Doctor
3.3.34
3.3.17
Often you need generic classes over elements of a single type, especially
for collections, e.g., lists, sets, bags of elements, ...
Generic classes abstract from the elements they work on, e.g., set of
integer, set of person, ...
Template class
Set
Set
insert(T)
insert(T)
includes(T)
includes(T)
Refinement
Bound class
Template parameter
Parameter binding
<<bind>>
<Person>
PersonSet
PersonSet
Note:
Note:In
InJava
Javathere
thereare
are
no
type
parameters
no type parametersor
or
templates.
templates.
3.3.35
Do not try to use all the notations available to you, if you do not have to.
Fit the perspective from which you are drawing the diagrams to the
stage of the project.
If you are in analysis, draw conceptual models.
When working with software, concentrate on specification.
Draw implementation models only when you are illustrating a particular
implementation technique.
Dont draw diagrams for everything; instead concentrate on the key areas.
3.3.36
3.3.18