Docsity

Problems with Multiple Inheritance - Object Oriented Programming - Lecture Slides, Slides of Object Oriented Programming

Partial preview of the text

Download Problems with Multiple Inheritance - Object Oriented Programming - Lecture Slides and more Slides Object Oriented Programming in PDF only on Docsity!

Object-Oriented Programming

(OOP)

Multiple Inheritance

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

Example – Multiple Inheritance

Mermaid

Woman Fish

Example – Multiple Inheritance

Amphibious Vehicle

Problems with Multiple

Inheritance

  • Increased complexity
  • Reduced understanding
  • Duplicate features

Problem – Duplicate Features

Mermaid

Woman Fish eat …

eat …

  • Which eat operation Mermaid inherits?

Problem – Duplicate Features

(Diamond Problem)

  • Which changeGear operation Amphibious Vehicle inherits?

Amphibious Vehicle

Land Vehicle Water Vehicle

Vehicle

Car Boat

changeGear

Solution to Diamond Problem

  • Some languages disallow diamond hierarchy
  • Others provide mechanism to ignore characteristics from one side

Kinds of Association

  • Class Association
    • Inheritance
  • Object Association
    • Simple Association
    • Composition
    • Aggregation

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”

One-way Association

  • We can navigate along a single direction only
  • Denoted by an arrow towards the server object

Example – Association

  • Ali lives in a House

Ali lives-in House (^11)

Two-way Association

  • We can navigate in both directions
  • Denoted by a line between the associated objects

Example – Two-way

Association

Employee works-for Company

  • 1
  • Employee works for company
  • Company employs employees