Professional Documents
Culture Documents
III. Class and Object Diagrams
III. Class and Object Diagrams
CSC340
Class Diagrams -- 1
CSC340
Classes
Class Diagrams -- 2
CSC340
Finding Classes
Class Diagrams -- 3
CSC340
StaffMember
Attributes
(optional)
Name (mandatory)
staffName
CalculateBonus()
ChangeGrade()
Operations
(optional)
Class Diagrams -- 4
CSC340
Names
Client
Campaign
StaffMember
Class Diagrams -- 5
CSC340
Attributes
Campaign
title: String
datePaid: Date
Class Diagrams -- 6
CSC340
SaveTheKids:Campaign
title: Save the kids
datePaid: 28/01/02
Class Diagrams -- 7
CSC340
Object Diagrams
Jaelson:Instructor
BillClinton
:Course
Monica:Student
someone:
courseNo: csc340"
description: OOAD"
Class Diagrams -- 8
CSC340
Multiobjects
A multiobject is a set of objects, with an undefined number of
elements
p2:Instructor
c1:Course
c3:Course
c2:Course
:Student
:Student
Multiobjects
Class Diagrams -- 9
CSC340
Operations
Class Diagrams -- 10
CSC340
Operations
Each operation
has a signature,
which specifies
the types of its
parameters and
the type of the
value it returns
(if any).
Campaign
Title:String
CampaignStartDate:Date
CampaignFinishDate:Date
EstimatedCost:Money
ActualCost:Money
CompletionDate:Date
DatePaid:Date
Completed(CompletionDate:Date,
ActualCost:Money)
SetFinishDate(FinishDate:Date)
RecordPayment(DatePaid:Date)
CostDifference():Money
Class Diagrams -- 11
CSC340
Visibility
protected
2003 John Mylopoulos
Staff
name : String
passwd : String
dateofB : Date
ChangePasswd()
Include()
Class Diagrams -- 12
CSC340
Relationships
Class Diagrams -- 13
CSC340
Generalization Relationship
Class Diagrams -- 14
CSC340
Generalization
StaffMember
staff#:Integer
name:String
startDate:Date
Hire()
ChangeGrade()
Class Diagrams -- 15
CSC340
Generalization
StaffMember
staff#:Integer
name:String
startDate:Date
grade
Hire()
ChangeGrade()
CalculateBonus()
AdminStaff
Hire()
CalculateBonus()
CreativeStaff
qualifications
Hire()
CalculateBonus()
Class Diagrams -- 16
CSC340
Generalization
Class Diagrams -- 17
CSC340
Finding Inheritance
Class Diagrams -- 18
CSC340
Advert
Hoarding*Advert
Press Advert
Video Advert
*Billboard
Newspaper Advert
Magazine Advert
Class Diagrams -- 19
CSC340
Finding Inheritance
RecordCD
title
catalogue#
publisher
artist
acquisition#
Loan()
Return()
Class Diagrams -- 20
CSC340
LoanItem
title
acquisition#
Loan()
Return()
...The
Solution...
Book
Author
DeweyCode
publisher
ISBN
Record
artist
catalogue#
recordCo
Class Diagrams -- 21
CSC340
Generalization Notation
Possibly overlapping
e.g., Maria is both Lecturer
and Student
Person
Student
Lecturer
Mutually exclusive
I.e., a lecturer cant be
a student and vice versa
Person
Student
Lecturer
Class Diagrams -- 22
CSC340
Class Diagrams -- 23
CSC340
Multiple Classification
TA
Male
Person
Female
sex
<<mandatory>>
student
Professor
role
<<dynamic>>
Student
Staff
Mandatory means that every instance of Person must be an
instance of Male or Female.
Dynamic means that an object can cease to be a TA and may
become a Professor.
2003 John Mylopoulos
Class Diagrams -- 24
CSC340
Association Relationship
StaffMemder
name
staff#
startDate
qualification
manages
Campaign
title
startDate
estimatedCost
Class Diagrams -- 25
CSC340
Association Multiplicity
Class Diagrams -- 26
CSC340
Campaign
name
staff#
startDate
qualification
manages
1
0..*
title
startDate
estimatedCost
A campaign is managed by
exactly one staff member
Class Diagrams -- 27
CSC340
Multiplicity
Optional (0 or 1)
Exactly one
Zero or more
One or more
A range of values
A set of ranges
0..1
1
= 1..1
0..* =
*
1..*
1..6
1..3,7..10,15,19..*
Class Diagrams -- 28
CSC340
Direction of an Association
StaffMember
name
staff#
startDate
qualification
Campaign
manages
title
startDate
estimatedCost
Class Diagrams -- 29
CSC340
Association Navigation
PersonName
Telephone#
Class Diagrams -- 30
CSC340
*
hires 1..* Person
employer
employee
supervisor 1
worker
*
Class Diagrams -- 31
CSC340
Association Classes
*
hires
employer
1..*
employee
Job
description
salary
2003 John Mylopoulos
Person
C a nt have the
same person
work for the
same company
more than once!
Class Diagrams -- 32
CSC340
Aggregation Relationship
Advert
contains
1
Class Diagrams -- 33
CSC340
Composition Relationship
Class Diagrams -- 34
CSC340
Order
-date: Date
-code: Integer
-total: Currency
An
Example
+Confirm()
+Cancel()
-Total():Currency
1
*
OrderItem
-quantity: Integer
-price: Currency
*
1
Product
Class Diagrams -- 35
CSC340
Another Example
composition
1..1
Engine
1..*
0..1
1..1
Car
Train
0..1
aggregation
0..1
1..1
driver
Person
1..1
driver
Class Diagrams -- 36
CSC340
These are like class diagrams, except now we model objects, i.e.,
instances of the classes defined in class diagrams.
Company
1
hires
employer
name:IBM Canada
addr:235 Eglinton
Person
Jack:
Person
hires
IBM:Company
1..*
employee
hires
Jeff:
Person
hires
Xerox:Company
name:Xerox Canada
addr:2 Bloor
Not
allowed!
Class Diagrams -- 37
CSC340
Business Rules
Class Diagrams -- 38
CSC340
Documentation Techniques
Class Diagrams -- 39
CSC340
Description
Employee working in the
company.
Attributes
Code, Surname,
Salary, Age
Identifier
Code
PROJECT
Name, Budget,
ReleaseDate
Name
....
....
....
....
Description
MANAGEMENT Associate a manager with
a department.
Entities involved
Employee (0,1),
Department (1,1)
Attributes
MEMBERSHIP
Associate an employee
with a department.
Employee (0,1)
Department (1,N)
StartDate
....
....
....
Associations
....
Class Diagrams -- 40
CSC340
Class Diagrams -- 41
CSC340
Class Diagrams -- 42
CSC340
Class Diagrams -- 43
CSC340
Class Diagrams -- 44
CSC340
Responsibilities
Class Diagrams -- 45
CSC340
Class Diagrams -- 46
CSC340
Im a Campaign ....
Im a Campaign. I know my title, start date, finish date and how
much I am estimated to cost.
When Ive been completed, I know how much I actually cost and
when I was completed. I can calculate the difference between my
actual and estimated costs.
When Ive been paid for, I know when the payment was made.
I can calculate the contribution made to me by each member of
staff who worked on me.
Class Diagrams -- 47
CSC340
Im a CreativeStaff ...
Im a CreativeStaff. I know my staff no, name, start date and
qualification.
I can calculate how much bonus I am entitled to at the end of
the year.
Does it make sense to include
I can calculate the contribution made to each campaign I have
worked on by each member of staff who worked on it.
,or does that belong in Campaign?
Class Diagrams -- 48
Class: Campaign
Responsibilities:
Title
StartDate
FinishDate
EstimatedCost
ActualCost
CompletionDate
DatePaid
AssignManager
RecordPayment
CSC340
Collaborating Classes
CreativeStaff
Completed
GetCampaignContribution
CostDifference
2003 John Mylopoulos
Class Diagrams -- 49
Class: CreativeStaff
Responsibilities:
CSC340
Collaborating Classes
StaffNo
StaffName
StaffStartDate
Qualification
CalculateBonus
ChangeGrade
Campaign
StaffGrade
Grade
Class Diagrams -- 50
CSC340
Additional Readings
Class Diagrams -- 51