Object oriented programming oop lecture no 5
Download
1 / 40

Object-Oriented Programming (OOP) Lecture No. 5 - PowerPoint PPT Presentation


  • 117 Views
  • Uploaded on

Object-Oriented Programming (OOP) Lecture No. 5. Multiple Inheritance. We may want to reuse characteristics of more than one parent class. Example – Multiple Inheritance. Mermaid. Example – Multiple Inheritance. Woman. Fish. Mermaid. Example – Multiple Inheritance. Amphibious Vehicle.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about ' Object-Oriented Programming (OOP) Lecture No. 5' - gagan


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
Object oriented programming oop lecture no 5

Object-Oriented Programming (OOP)Lecture No. 5

Downloaded From: www.bsit.zxq.net


Multiple inheritance
Multiple Inheritance

  • We may want to reuse characteristics of more than one parent class

Downloaded From: www.bsit.zxq.net


Example multiple inheritance
Example – Multiple Inheritance

Mermaid

Downloaded From: www.bsit.zxq.net


Example multiple inheritance1
Example – Multiple Inheritance

Woman

Fish

Mermaid

Downloaded From: www.bsit.zxq.net


Example multiple inheritance2
Example – Multiple Inheritance

Amphibious Vehicle

Downloaded From: www.bsit.zxq.net


Example multiple inheritance3
Example – Multiple Inheritance

Vehicle

Land Vehicle

Water Vehicle

Car

Amphibious Vehicle

Boat

Downloaded From: www.bsit.zxq.net


Problems with multiple inheritance
Problems with Multiple Inheritance

  • Increased complexity

  • Reduced understanding

  • Duplicate features

Downloaded From: www.bsit.zxq.net


Problem duplicate features
Problem – Duplicate Features

  • Which eat operation Mermaid inherits?

Woman

Fish

eat

eat

Mermaid

Downloaded From: www.bsit.zxq.net


Solution override the common feature
Solution – Override the Common Feature

Woman

Fish

eat

eat

Mermaid

Invoke eat operation of desired class

eat

Downloaded From: www.bsit.zxq.net


Problem duplicate features diamond problem
Problem – Duplicate Features (Diamond Problem)

Vehicle

  • Which changeGear operation Amphibious Vehicle inherits?

changeGear

Land Vehicle

Water Vehicle

Car

Amphibious Vehicle

Boat

Downloaded From: www.bsit.zxq.net


Solution to diamond problem
Solution to Diamond Problem

  • Some languages disallow diamond hierarchy

  • Others provide mechanism to ignore characteristics from one side

Downloaded From: www.bsit.zxq.net


Association
Association

  • Objects in an object model interact with each other

  • Usually an object provides services to several other objects

  • An object keeps associations with other objects to delegate tasks

Downloaded From: www.bsit.zxq.net


Kinds of association
Kinds of Association

  • Class Association

    • Inheritance

  • Object Association

    • Simple Association

    • Composition

    • Aggregation

Downloaded From: www.bsit.zxq.net


Simple association
Simple Association

  • Is the weakest link between objects

  • Is a reference by which one object can interact with some other object

  • Is simply called as “association”

Downloaded From: www.bsit.zxq.net


Kinds of simple association
Kinds of Simple Association

  • w.r.t navigation

    • One-way Association

    • Two-way Association

  • w.r.t number of objects

    • Binary Association

    • Ternary Association

    • N-ary Association

Downloaded From: www.bsit.zxq.net


One way association
One-way Association

  • We can navigate along a single direction only

  • Denoted by an arrow towards the server object

Downloaded From: www.bsit.zxq.net


Example association
Example – Association

  • Ali lives in a House

Ali

lives-in

House

1

1

Downloaded From: www.bsit.zxq.net


Example association1
Example – Association

  • Ali drives his Car

Ali

drives

Car

1

*

Downloaded From: www.bsit.zxq.net


Two way association
Two-way Association

  • We can navigate in both directions

  • Denoted by a line between the associated objects

Downloaded From: www.bsit.zxq.net


Example two way association
Example – Two-way Association

  • Employee works for company

  • Company employs employees

Employee

works-for

Company

*

1

Downloaded From: www.bsit.zxq.net


Example two way association1
Example – Two-way Association

  • Yasir is a friend of Ali

  • Ali is a friend of Yasir

Yasir

friend

Ali

1

1

Downloaded From: www.bsit.zxq.net


Binary association
Binary Association

  • Associates objects of exactly two classes

  • Denoted by a line, or an arrow between the associated objects

Downloaded From: www.bsit.zxq.net


Example binary association
Example – Binary Association

  • Association “works-for” associates objects of exactly two classes

Employee

works-for

Company

*

1

Downloaded From: www.bsit.zxq.net


Example binary association1
Example – Binary Association

  • Association “drives” associates objects of exactly two classes

Ali

drives

Car

1

*

Downloaded From: www.bsit.zxq.net


Ternary association
Ternary Association

  • Associates objects of exactly three classes

  • Denoted by a diamond with lines connected to associated objects

Downloaded From: www.bsit.zxq.net


Example ternary association
Example – Ternary Association

  • Objects of exactly three classes are associated

Student

Teacher

1

*

*

Course

Downloaded From: www.bsit.zxq.net


Example ternary association1
Example – Ternary Association

  • Objects of exactly three classes are associated

Project

Language

*

*

1

Person

Downloaded From: www.bsit.zxq.net


N ary association
N-ary Association

  • An association between 3 or more classes

  • Practical examples are very rare

Downloaded From: www.bsit.zxq.net


Composition
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

Downloaded From: www.bsit.zxq.net


Example composition of ali
Example – Composition of Ali

Head

1

Arm

Leg

Ali

2

2

1

Body

Downloaded From: www.bsit.zxq.net


Example composition of chair
Example – Composition of Chair

Back

1

Chair

1

2

4

Arm

Seat

Leg

Downloaded From: www.bsit.zxq.net


Composition is stronger
Composition is Stronger

  • Composition is a stronger relationship, because

    • Composed object becomes a part of the composer

    • Composed object can’t exist independently

Downloaded From: www.bsit.zxq.net


Example composition is stronger
Example – Composition is Stronger

  • Ali is made up of different body parts

  • They can’t exist independent of Ali

Downloaded From: www.bsit.zxq.net


Example composition is stronger1
Example – Composition is Stronger

  • Chair’s body is made up of different parts

  • They can’t exist independently

Downloaded From: www.bsit.zxq.net


Aggregation
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

Downloaded From: www.bsit.zxq.net


Example aggregation
Example – Aggregation

Bed

1

Chair

Room

Table

*

1

1

Cupboard

Downloaded From: www.bsit.zxq.net


Example aggregation1
Example – Aggregation

Garden

Plant

*

Downloaded From: www.bsit.zxq.net


Aggregation is weaker
Aggregation is Weaker

  • Aggregation is weaker relationship, because

    • Aggregate object is not a part of the container

    • Aggregate object can exist independently

Downloaded From: www.bsit.zxq.net


Example aggregation is weaker
Example – Aggregation is Weaker

  • Furniture is not an intrinsic part of room

  • Furniture can be shifted to another room, and so can exist independent of a particular room

Downloaded From: www.bsit.zxq.net


Example aggregation is weaker1
Example – Aggregation is Weaker

  • A plant is not an intrinsic part of a garden

  • It can be planted in some other garden, and so can exist independent of a particular garden

Downloaded From: www.bsit.zxq.net


ad