Object Oriented
Design
and
Programming
Cristiano Calcagno (weeks 3-8)
and
William Knottenbelt (weeks 9-11)
Introduction to UML
Objective
Introduction to UML
Requirements
System
in use
Commission
Analysis
Tested
System
Specification
Integrate
Design
Tested
Subsystems
Architecture
Implementation
Test
Code
Introduction to UML
Introduction to UML
Course Operation
Lectures
Exam Questions
1.
2.
3.
Assessment
Introduction to UML
Introduction to UML
AddisonAddison-Wesley.
C++: How to program, Deitel & Deitel,
Deitel, Prentice
Hall.
Introduction to UML
Introduction to UML
Introduction to UML
blueCar: Car
: Car
10
Introduction to UML
Introduction to UML
11
Introduction to UML
12
redRar: Car
sophia: Driver
Attributes
Attributes are properties of, or data held in, an object.
carl: Passenger
blueRar: Car
mileage: 44000
colour: "blue"
blueRar: Car
:TrafficLight
:TrafficLight
ali: Pedestrian
13
blueBird: Car
mileage: 44000
horsepower: 500
Introduction to UML
ali: Passenger
favourite: "Programming"
Introduction to UML
For example:
Passenger
weight :float
Passenger
weight: float
14
Car
mileage: int
colour: String
Operations
blueCar: Car
mileage: 44
colour: "blue"
carl: Passenger
weight: 67,88
15
Introduction to UML
Student
age: int
name: String
void register(course,date)
void changeCourse(course)
int getGrade(course)
16
Operations (2)
Student
age: int
name: String
Introduction to UML
17
Introduction to UML
18
Introduction to UML
19
Introduction to UML
20
Operations (3)
Operations (4)
and
Introduction to UML
Car
age: int
horsePower: int
float speed( )
21
-- Who
Introduction to UML
22
Associations
Association name
Person
Company
3rd
Introduction to UML
23
Association
Introduction to UML
24
Multiple associations
Multiplicity
Person
Introduction to UML
Flight
0..m Company
1..n
employee
Flies-from
Aiport
Flies-to
Multiplicity
(Cardinality)
Role
Flight
departures
**
arrivals
from Aiport
1
1
destination
employer
Object Oriented Design and Programming, 2006-2007
association
names
association roles
25
Introduction to UML
26
leah: Woman
child
child
jakob: Man
rachel: Woman
child
child
child
child
reuben: Man
married
simeon: Man
benjamin: Man
27
Introduction to UML
28
Associations vs Attributes
Associations exist between objects; attributes have simple
type (not objects).
Therefore
Being mother of a person is represented through
29
Introduction to UML
being married to
applying for a driver
drivers license
meeting a colleague
being friends with
owning a car
riding a bicycle
a plane landing at airport
Introduction to UML
marrying somebody
divorcing somebody
belonging to a club
working for a company
selling a house
owning a house
moving into a flat
30
Aggregation
Associations vs Operations
Shared Aggregation
Composition
Note: For this course, we do not insist on the difference
between shared aggregation and composition .
We do insist on the difference between aggregation and
association.
31
Introduction to UML
32
Shared Aggregation
1
College
*
Department
Composition
*
TaughtCourses
Students
Under Composition,
an element can be
part of at most one
aggregate
Introduction to UML
Header 1
EMailMessage
*
Body
0..n
Attachment
33
Introduction to UML
34
35
Introduction to UML
36
Introduction to UML
Associations vs Aggregations
Association Classes
Therefore, we represent
a department as part of a the College as :
worksFor
Person
Company
1..n
Contract
???
The employment is
subject to a contract
specifying start date,
salary, etc.
startDate:Date
salary:int
Object Oriented Design and Programming, 2006-2007
Introduction to UML
37
worksFor
Company
1..n
Contract
38
Introduction to UML
startDate:Date
salary:int
worksFor
Person
Company
1..n
*
Contract
startDate:Date
salary:int
Introduction to UML
39
Introduction to UML
40
Introduction to UML
41
Generalization
Introduction to UML
42
Generalization Example
Element
File
Directory
Introduction to UML
43
Introduction to UML
44
Class_C and
Class_D implement
method() in different
ways
Class_A
method()
Class_C
method()
Class_D
method()
Introduction to UML
45
Introduction to UML
46
Introduction to UML
47
Introduction to UML
48
Parallel Hierarchies
Sometimes an association is refined in a subclass.
Person
Company
Contract
startDate:Date
salary:int
Company
Contract
startDate:Date
salary:int
Trader
Trader
SpecialContract
SpecialContract
bonus:long
Introduction to UML
bonus:long
49
Introduction to UML
50
Bank
Bank
51
Introduction to UML
52
Introduction to UML
53
Introduction to UML
54
operation_1(Class_B x)
vs
operation_1(Property_B x)
The answer is
because
Introduction to UML
55
Introduction to UML
56