Object Oriented Programming (OOP) - CS304 Power Point Slides Lecture 05
Object Oriented Programming (OOP) - CS304 Power Point Slides Lecture 05
Multiple Inheritance
We
Mermaid
Woman
Fish
Mermaid
Amphibious Vehicle
Land Vehicle
Water Vehicle
Car
Amphibious Vehicle
Boat
complexity
understanding
features
Fish
Mermaid
Which
Fish
Mermaid
eat
Land Vehicle
Water Vehicle
Car
Which
Amphibious Vehicle
Boat
Vehicle inherits?
languages disallow diamond hierarchy provide mechanism to ignore characteristics from one side
Others
Association
Objects
in an object model interact with each other an object provides services to several other objects
Usually
An
Kinds of Association
Class
Association
Inheritance
Object
Association
Simple Association
Is
Is
a reference by which one object can interact with some other object simply called as association
Is
navigation
number of objects
One-way Association
We
Denoted
object
Example Association
Ali
lives-in
1 1
House
Ali
lives in a House
Example Association
Ali
drives
1 *
Car
Ali
Two-way Association
We
Denoted
objects
Employee
works-for
* 1
Company
Employee
Yasir
friend
1 1
Ali
Yasir
Binary Association
Associates
Denoted
Employee
works-for
* 1
Company
Association
Ali
drives
1 *
Car
Association
Ternary Association
Associates
Denoted
Teacher 1
Course
Objects
Language *
Person
Objects
N-ary Association
An
Practical
Composition
An
object may be composed of other smaller objects The relationship between the part objects and the whole object is known as Composition Composition is represented by a line with a filled-diamond head towards the composer object
Arm
Ali
Leg
1 Body
Chair
2 Arm
1 Seat
4 Leg
Composition is Stronger
Composition
because
is a stronger relationship,
Composed object becomes a part of the composer Composed object cant exist independently
They
Aggregation
An
object may contain a collection (aggregate) of other objects The relationship between the container and the contained object is called aggregation Aggregation is represented by a line with unfilled-diamond head towards the container
Example Aggregation
Bed 1
Chair
Room
Table
1 Cupboard
Example Aggregation
Garden
Plant
Aggregation is Weaker
Aggregation
Aggregate object is not a part of the container Aggregate object can exist independently
can be shifted to another room, and so can exist independent of a particular room
can be planted in some other garden, and so can exist independent of a particular garden