SlideShare a Scribd company logo
Introduction Multiple Inheritance Name Ambiguity Common Ancestors Inner Classes Summary References
MULTIPLE INHERITANCE
Muhammad Adil Raja
Roaming Researchers, Inc.
cbna
April 20, 2015
Introduction Multiple Inheritance Name Ambiguity Common Ancestors Inner Classes Summary References
OUTLINE I
INTRODUCTION
MULTIPLE INHERITANCE
NAME AMBIGUITY
COMMON ANCESTORS
INNER CLASSES
SUMMARY
REFERENCES
Introduction Multiple Inheritance Name Ambiguity Common Ancestors Inner Classes Summary References
INTRODUCTION
• We will investigate some of the problems that can arize
when a language allows a child class to have multiple
parents.
• Name ambiguity.
• Impact on substitution.
• The Problem of Common Ancestors.
Introduction Multiple Inheritance Name Ambiguity Common Ancestors Inner Classes Summary References
THE IDEALIZATION OF IS-A RELATIONSHIP
MESSAGE SYNTAX
• In one sense, the process of inheritance is a form of
categorization. A TextWindow is a type of Window, so
class TextWindow inherits from class Window.
• But in the real world, most objects can be categorized in a
variety of ways.
• The author of the textbook is:
• North American.
• Male.
• Professor.
• Parent.
• None of these are proper subsets of the other, and we
cannot make a single rooted inheritance hierarchy out of
them.
Introduction Multiple Inheritance Name Ambiguity Common Ancestors Inner Classes Summary References
INHERITANCE AS COMBINATION
• Instead, real world objects are combinations of features
from different classification schemes, each category giving
some new insight into the whole:
• Author is North American, and
• Author is Male, and
• Author is a Professor, and
• Author is a Parent.
• Note that we have not lost the is-a relationship; it still
applies in each case.
Introduction Multiple Inheritance Name Ambiguity Common Ancestors Inner Classes Summary References
CS EXAMPLE – COMPLEX NUMBERS
Two abstract classifications
• Magnitude – things that can be compared to each other.
• Number – things that can perform arithmetic.
Three specific classes
• Integer – comparable and arithmetic.
• Char – comparable but not arithmetic.
• Complex – arithmetic but not comparable.
Introduction Multiple Inheritance Name Ambiguity Common Ancestors Inner Classes Summary References
POSSIBLE SOLUTIONS
1. Make Number subclass of Magnitude, but redefine
comparison operators in class complex to give error
message if used. (subclassing for limitation)
2. Don’t use inheritance at all – redefine all operators in all
classes. (flattening the inheritance tree).
3. Use part inheritance, but simulate others – use Number,
but have each number implement all relational operators.
4. Make Number and Magnitude independent, and have
Integer inherit from both. (multiple inheritance).
Introduction Multiple Inheritance Name Ambiguity Common Ancestors Inner Classes Summary References
INHERITANCE AS A FORM OF COMBINATION
FIGURE : Inheritance.
Introduction Multiple Inheritance Name Ambiguity Common Ancestors Inner Classes Summary References
ANOTHER EXAMPLE – WALKING MENUS
• A Menu is a structure charged with displaying itself when
selected by the user.
• A
• Menu maintains a collection of MenuItems.
• Each MenuItem knows how to respond when selected.
• A cascading menu is both a MenuItem and a Menu.
Introduction Multiple Inheritance Name Ambiguity Common Ancestors Inner Classes Summary References
PROBLEM WITH MI – NAME AMBUITY
• What happens when same name is used in both parent
classes.
• A
• CardDeck knows how to draw a Card.
• A GraphicalItem knows how to draw an image on a
screen.
• A GraphicalCardDeck should be able to draw. which?
Introduction Multiple Inheritance Name Ambiguity Common Ancestors Inner Classes Summary References
ONE SOLUTION – REDEFINITION
One solution is to redefine one or the other operation in the
child class.
REDEFINITION
class GraphicalCardDeck : public CardDeck , public GraphicalObject {
public :
virtual void draw ( ) { return CardDeck : : draw ( ) ; }
virtual void paint ( ) { GraphicalObject : : draw ( ) ; }
}
GraphicalCardDeck gcd ;
gcd−>draw ( ) ; / / selects CardDeck draw
gcd−>paint ( ) ; / / selects GraphicalObject draw
Introduction Multiple Inheritance Name Ambiguity Common Ancestors Inner Classes Summary References
PROBLEM WITH REDEFINITION SOLUTION
• The redefinition solution is not without cost, however.
• Now what happens when we run up against the principle of
substitution?
REDEFINITION
GraphicalObject ∗ g = new GraphicalCardDeck ( ) ;
g−>draw ( ) ; / / opps , doing wrong method !
This problem can be mitigated, but the solution is complex and
not perfect.
Introduction Multiple Inheritance Name Ambiguity Common Ancestors Inner Classes Summary References
OTHER APPROACHES TO NAME AMBIGUITY
• Other languages use different approaches to solving the
problem of ambiguous names.
• Eiffel uses the ability to rename features from the parent
class.
• A polymorphic variable accessing through the parents
name will access the renamed feature in the child.
• CLOS and Python resolve ambiguous names by the order
in which the parent classes are listed.
• The first occurrence of the name found in a systematic
search is the one selected.
Introduction Multiple Inheritance Name Ambiguity Common Ancestors Inner Classes Summary References
MULTIPLE INHERITANCE OF INTERFACES
• Multiple inheritance of interfaces does not present the
same problem of name ambiguity as does multiple
inheritance of classes.
• Either the ambiguous methods in the parent classes have
different type signatures, in which case there is no
problem, or
• The ambiguous methods in the parent classes have the
same signature. Still no problem, since what is inherited is
only a specification, not an implementation.
• This is why Java permits multiple inheritance of interfaces,
not of classes. Nevertheless, C# does not permit the same
method name to be inherited from two parent interfaces.
Introduction Multiple Inheritance Name Ambiguity Common Ancestors Inner Classes Summary References
INHERITANCE FROM COMMON ANCESTORS
• Another problem with MI occurs when parent classes have
a common root ancestor.
• Does the new object have one or two instances of the
ancestor?
FIGURE : Inheritance from common ancestors.
Introduction Multiple Inheritance Name Ambiguity Common Ancestors Inner Classes Summary References
DATA FIELD IN COMMON ANCESTOR
• Imagine that the common ancestor declares a data
member. Should the child class have one copy of this data
field, or two?
• Both answers can be justified with examples.
• C++ gets around this by introducing the idea of a virtual
parent class.
• If your parent is virtual there is one copy, and if not there is
two.
• Not a perfect solution, and makes the language
complicated.
Introduction Multiple Inheritance Name Ambiguity Common Ancestors Inner Classes Summary References
INNER CLASSES
• The ability to next classes in C++ and Java provides a
mechanism that is nearly equivalent to multiple
inheritance, without the semantic problems.
INNER CLASS
class Child extends ParentOne {
. . .
class InnerChild extends ParentTwo {
. . .
/ / can access both parents
}
}
Introduction Multiple Inheritance Name Ambiguity Common Ancestors Inner Classes Summary References
SUMMARY
• In this chapter we have explored some of the problems that
arise of the concept of multiple inheritance.
• Name ambiguity.
• Impact on substitution.
• The Problem of Common Ancestors.
Introduction Multiple Inheritance Name Ambiguity Common Ancestors Inner Classes Summary References
REFERENCES
• Images and content for developing these slides have been
taken from the follwoing book with the permission of the
author.
• An Introduction to Object Oriented Programming, Timothy
Budd.
• This presentation is developed using Beamer:
• Singapore, wolverine.

More Related Content

PPTX
Static Members-Java.pptx
PPTX
Operators in java
PPTX
Unary operator overloading
PPT
Literals,variables,datatype in C#
PPT
Java oops and fundamentals
PPTX
Ppt on this and super keyword
PPT
Input and output in C++
PPT
Operators in C++
Static Members-Java.pptx
Operators in java
Unary operator overloading
Literals,variables,datatype in C#
Java oops and fundamentals
Ppt on this and super keyword
Input and output in C++
Operators in C++

What's hot (20)

PDF
Overriding
PPTX
Inheritance in c++
PPTX
inheritance
PDF
Operator overloading
PPTX
Constructor and destructor
PPTX
Polymorphism in java
PPTX
Function C++
PPTX
This keyword in java
PPTX
Polymorphism In c++
PPTX
Abstract class in c++
PPTX
Operators in java presentation
DOCX
Encapsulation in C++
PPTX
JAVA LOOP.pptx
PPTX
Java Program Structure
PPTX
What is Switch Case?
PPTX
virtual function
PPTX
classes and objects in C++
PPTX
Function overloading
PPTX
Type casting in java
PPTX
Polymorphism in java
Overriding
Inheritance in c++
inheritance
Operator overloading
Constructor and destructor
Polymorphism in java
Function C++
This keyword in java
Polymorphism In c++
Abstract class in c++
Operators in java presentation
Encapsulation in C++
JAVA LOOP.pptx
Java Program Structure
What is Switch Case?
virtual function
classes and objects in C++
Function overloading
Type casting in java
Polymorphism in java
Ad

Viewers also liked (19)

PPTX
Inheritance in OOPS
PDF
I2C programming with C and Arduino
PPT
Protols used in bluetooth
PDF
Introduction to Embedded System
PDF
Object-Oriented Design: Multiple inheritance (C++ and C#)
PPTX
I2C Protocol
PPTX
Compiler in System Programming/Code Optimization techniques in System Program...
PPT
Arm processor
ODP
Arm developement
PPTX
Serial Peripheral Interface
PDF
Embedded C - Optimization techniques
PDF
SPI Protocol
PDF
I2C Bus (Inter-Integrated Circuit)
PDF
Embedded C - Lecture 1
PPTX
Serial peripheral interface
PPT
Serial Peripheral Interface(SPI)
PPT
Code Optimization
PPTX
Inheritance in OOPS
I2C programming with C and Arduino
Protols used in bluetooth
Introduction to Embedded System
Object-Oriented Design: Multiple inheritance (C++ and C#)
I2C Protocol
Compiler in System Programming/Code Optimization techniques in System Program...
Arm processor
Arm developement
Serial Peripheral Interface
Embedded C - Optimization techniques
SPI Protocol
I2C Bus (Inter-Integrated Circuit)
Embedded C - Lecture 1
Serial peripheral interface
Serial Peripheral Interface(SPI)
Code Optimization
Ad

Similar to Multiple Inheritance (20)

PPTX
Polymorphism
PDF
Inheritance and Substitution
PDF
Java programming -Object-Oriented Thinking- Inheritance
PPTX
java_inheritance_oop_20250730110153.pptx
PPT
Multiple Inheritance powerpoint presentation
PPTX
Multiple inheritance in java3 (1).pptx
PPTX
INHERITANCE-Oopc ppt-ta4
PPTX
SAD04 - Inheritance
PPTX
SKILLWISE - OOPS CONCEPT
PPT
Java_notes.ppt
DOC
How would you implement multiple inheritance in java
PPTX
Java OOPS Concept
PPTX
Concepts of oop1
PPTX
CSharp_03_Inheritance_introduction_with_examples
PPTX
Introduction to oop and java fundamentals
PPTX
OOPS (Object Oriented Programming System) CONCEPTS
PPTX
2CPP07 - Inheritance
PDF
Lecture on Python OP concepts of Polymorpysim and Inheritance.pdf
PPTX
Multiple inheritance possible in Java
Polymorphism
Inheritance and Substitution
Java programming -Object-Oriented Thinking- Inheritance
java_inheritance_oop_20250730110153.pptx
Multiple Inheritance powerpoint presentation
Multiple inheritance in java3 (1).pptx
INHERITANCE-Oopc ppt-ta4
SAD04 - Inheritance
SKILLWISE - OOPS CONCEPT
Java_notes.ppt
How would you implement multiple inheritance in java
Java OOPS Concept
Concepts of oop1
CSharp_03_Inheritance_introduction_with_examples
Introduction to oop and java fundamentals
OOPS (Object Oriented Programming System) CONCEPTS
2CPP07 - Inheritance
Lecture on Python OP concepts of Polymorpysim and Inheritance.pdf
Multiple inheritance possible in Java

More from adil raja (20)

PDF
ANNs.pdf
PDF
A Software Requirements Specification
PDF
NUAV - A Testbed for Development of Autonomous Unmanned Aerial Vehicles
PDF
DevOps Demystified
PDF
On Research (And Development)
PDF
Simulators as Drivers of Cutting Edge Research
PDF
The Knock Knock Protocol
PDF
File Transfer Through Sockets
PDF
Remote Command Execution
PDF
Thesis
PDF
CMM Level 3 Assessment of Xavor Pakistan
PDF
Data Warehousing
PDF
Implementation of a Non-Intrusive Speech Quality Assessment Tool on a Mid-Net...
PDF
Implementation of a Non-Intrusive Speech Quality Assessment Tool on a Mid-Net...
PDF
Real-Time Non-Intrusive Speech Quality Estimation for VoIP
PDF
VoIP
PDF
ULMAN GUI Specifications
PDF
Modeling the Effect of Packet Loss on Speech Quality: Genetic Programming Bas...
PDF
ULMAN-GUI
PDF
Modeling the Effect of Packet Loss on Speech Quality: Genetic Programming Bas...
ANNs.pdf
A Software Requirements Specification
NUAV - A Testbed for Development of Autonomous Unmanned Aerial Vehicles
DevOps Demystified
On Research (And Development)
Simulators as Drivers of Cutting Edge Research
The Knock Knock Protocol
File Transfer Through Sockets
Remote Command Execution
Thesis
CMM Level 3 Assessment of Xavor Pakistan
Data Warehousing
Implementation of a Non-Intrusive Speech Quality Assessment Tool on a Mid-Net...
Implementation of a Non-Intrusive Speech Quality Assessment Tool on a Mid-Net...
Real-Time Non-Intrusive Speech Quality Estimation for VoIP
VoIP
ULMAN GUI Specifications
Modeling the Effect of Packet Loss on Speech Quality: Genetic Programming Bas...
ULMAN-GUI
Modeling the Effect of Packet Loss on Speech Quality: Genetic Programming Bas...

Recently uploaded (20)

PPTX
Benefits of DCCM for Genesys Contact Center
PDF
How Creative Agencies Leverage Project Management Software.pdf
PDF
PTS Company Brochure 2025 (1).pdf.......
PDF
Jenkins: An open-source automation server powering CI/CD Automation
PDF
Best Practices for Rolling Out Competency Management Software.pdf
PDF
Rise With SAP partner in Mumbai.........
PDF
How to Confidently Manage Project Budgets
PDF
Become an Agentblazer Champion Challenge
PDF
Sensix-Tech-Pvt-Ltd-Company-Profile (1).pdf
PPTX
Maximizing Revenue with Marketo Measure: A Deep Dive into Multi-Touch Attribu...
PDF
Teaching Reproducibility and Embracing Variability: From Floating-Point Exper...
PPTX
How a Careem Clone App Allows You to Compete with Large Mobility Brands
PDF
Comprehensive Salesforce Implementation Services.pdf
PPTX
Using Bootstrap to Make Accessible Front-Ends(2).pptx
PDF
ShowUs: Pharo Stream Deck (ESUG 2025, Gdansk)
PPTX
10 Hidden App Development Costs That Can Sink Your Startup.pptx
PDF
The Future of Smart Factories Why Embedded Analytics Leads the Way
PPTX
Save Business Costs with CRM Software for Insurance Agents
PPTX
Hire Expert Blazor Developers | Scalable Solutions by OnestopDA
PDF
Become an Agentblazer Champion Challenge Kickoff
Benefits of DCCM for Genesys Contact Center
How Creative Agencies Leverage Project Management Software.pdf
PTS Company Brochure 2025 (1).pdf.......
Jenkins: An open-source automation server powering CI/CD Automation
Best Practices for Rolling Out Competency Management Software.pdf
Rise With SAP partner in Mumbai.........
How to Confidently Manage Project Budgets
Become an Agentblazer Champion Challenge
Sensix-Tech-Pvt-Ltd-Company-Profile (1).pdf
Maximizing Revenue with Marketo Measure: A Deep Dive into Multi-Touch Attribu...
Teaching Reproducibility and Embracing Variability: From Floating-Point Exper...
How a Careem Clone App Allows You to Compete with Large Mobility Brands
Comprehensive Salesforce Implementation Services.pdf
Using Bootstrap to Make Accessible Front-Ends(2).pptx
ShowUs: Pharo Stream Deck (ESUG 2025, Gdansk)
10 Hidden App Development Costs That Can Sink Your Startup.pptx
The Future of Smart Factories Why Embedded Analytics Leads the Way
Save Business Costs with CRM Software for Insurance Agents
Hire Expert Blazor Developers | Scalable Solutions by OnestopDA
Become an Agentblazer Champion Challenge Kickoff

Multiple Inheritance

  • 1. Introduction Multiple Inheritance Name Ambiguity Common Ancestors Inner Classes Summary References MULTIPLE INHERITANCE Muhammad Adil Raja Roaming Researchers, Inc. cbna April 20, 2015
  • 2. Introduction Multiple Inheritance Name Ambiguity Common Ancestors Inner Classes Summary References OUTLINE I INTRODUCTION MULTIPLE INHERITANCE NAME AMBIGUITY COMMON ANCESTORS INNER CLASSES SUMMARY REFERENCES
  • 3. Introduction Multiple Inheritance Name Ambiguity Common Ancestors Inner Classes Summary References INTRODUCTION • We will investigate some of the problems that can arize when a language allows a child class to have multiple parents. • Name ambiguity. • Impact on substitution. • The Problem of Common Ancestors.
  • 4. Introduction Multiple Inheritance Name Ambiguity Common Ancestors Inner Classes Summary References THE IDEALIZATION OF IS-A RELATIONSHIP MESSAGE SYNTAX • In one sense, the process of inheritance is a form of categorization. A TextWindow is a type of Window, so class TextWindow inherits from class Window. • But in the real world, most objects can be categorized in a variety of ways. • The author of the textbook is: • North American. • Male. • Professor. • Parent. • None of these are proper subsets of the other, and we cannot make a single rooted inheritance hierarchy out of them.
  • 5. Introduction Multiple Inheritance Name Ambiguity Common Ancestors Inner Classes Summary References INHERITANCE AS COMBINATION • Instead, real world objects are combinations of features from different classification schemes, each category giving some new insight into the whole: • Author is North American, and • Author is Male, and • Author is a Professor, and • Author is a Parent. • Note that we have not lost the is-a relationship; it still applies in each case.
  • 6. Introduction Multiple Inheritance Name Ambiguity Common Ancestors Inner Classes Summary References CS EXAMPLE – COMPLEX NUMBERS Two abstract classifications • Magnitude – things that can be compared to each other. • Number – things that can perform arithmetic. Three specific classes • Integer – comparable and arithmetic. • Char – comparable but not arithmetic. • Complex – arithmetic but not comparable.
  • 7. Introduction Multiple Inheritance Name Ambiguity Common Ancestors Inner Classes Summary References POSSIBLE SOLUTIONS 1. Make Number subclass of Magnitude, but redefine comparison operators in class complex to give error message if used. (subclassing for limitation) 2. Don’t use inheritance at all – redefine all operators in all classes. (flattening the inheritance tree). 3. Use part inheritance, but simulate others – use Number, but have each number implement all relational operators. 4. Make Number and Magnitude independent, and have Integer inherit from both. (multiple inheritance).
  • 8. Introduction Multiple Inheritance Name Ambiguity Common Ancestors Inner Classes Summary References INHERITANCE AS A FORM OF COMBINATION FIGURE : Inheritance.
  • 9. Introduction Multiple Inheritance Name Ambiguity Common Ancestors Inner Classes Summary References ANOTHER EXAMPLE – WALKING MENUS • A Menu is a structure charged with displaying itself when selected by the user. • A • Menu maintains a collection of MenuItems. • Each MenuItem knows how to respond when selected. • A cascading menu is both a MenuItem and a Menu.
  • 10. Introduction Multiple Inheritance Name Ambiguity Common Ancestors Inner Classes Summary References PROBLEM WITH MI – NAME AMBUITY • What happens when same name is used in both parent classes. • A • CardDeck knows how to draw a Card. • A GraphicalItem knows how to draw an image on a screen. • A GraphicalCardDeck should be able to draw. which?
  • 11. Introduction Multiple Inheritance Name Ambiguity Common Ancestors Inner Classes Summary References ONE SOLUTION – REDEFINITION One solution is to redefine one or the other operation in the child class. REDEFINITION class GraphicalCardDeck : public CardDeck , public GraphicalObject { public : virtual void draw ( ) { return CardDeck : : draw ( ) ; } virtual void paint ( ) { GraphicalObject : : draw ( ) ; } } GraphicalCardDeck gcd ; gcd−>draw ( ) ; / / selects CardDeck draw gcd−>paint ( ) ; / / selects GraphicalObject draw
  • 12. Introduction Multiple Inheritance Name Ambiguity Common Ancestors Inner Classes Summary References PROBLEM WITH REDEFINITION SOLUTION • The redefinition solution is not without cost, however. • Now what happens when we run up against the principle of substitution? REDEFINITION GraphicalObject ∗ g = new GraphicalCardDeck ( ) ; g−>draw ( ) ; / / opps , doing wrong method ! This problem can be mitigated, but the solution is complex and not perfect.
  • 13. Introduction Multiple Inheritance Name Ambiguity Common Ancestors Inner Classes Summary References OTHER APPROACHES TO NAME AMBIGUITY • Other languages use different approaches to solving the problem of ambiguous names. • Eiffel uses the ability to rename features from the parent class. • A polymorphic variable accessing through the parents name will access the renamed feature in the child. • CLOS and Python resolve ambiguous names by the order in which the parent classes are listed. • The first occurrence of the name found in a systematic search is the one selected.
  • 14. Introduction Multiple Inheritance Name Ambiguity Common Ancestors Inner Classes Summary References MULTIPLE INHERITANCE OF INTERFACES • Multiple inheritance of interfaces does not present the same problem of name ambiguity as does multiple inheritance of classes. • Either the ambiguous methods in the parent classes have different type signatures, in which case there is no problem, or • The ambiguous methods in the parent classes have the same signature. Still no problem, since what is inherited is only a specification, not an implementation. • This is why Java permits multiple inheritance of interfaces, not of classes. Nevertheless, C# does not permit the same method name to be inherited from two parent interfaces.
  • 15. Introduction Multiple Inheritance Name Ambiguity Common Ancestors Inner Classes Summary References INHERITANCE FROM COMMON ANCESTORS • Another problem with MI occurs when parent classes have a common root ancestor. • Does the new object have one or two instances of the ancestor? FIGURE : Inheritance from common ancestors.
  • 16. Introduction Multiple Inheritance Name Ambiguity Common Ancestors Inner Classes Summary References DATA FIELD IN COMMON ANCESTOR • Imagine that the common ancestor declares a data member. Should the child class have one copy of this data field, or two? • Both answers can be justified with examples. • C++ gets around this by introducing the idea of a virtual parent class. • If your parent is virtual there is one copy, and if not there is two. • Not a perfect solution, and makes the language complicated.
  • 17. Introduction Multiple Inheritance Name Ambiguity Common Ancestors Inner Classes Summary References INNER CLASSES • The ability to next classes in C++ and Java provides a mechanism that is nearly equivalent to multiple inheritance, without the semantic problems. INNER CLASS class Child extends ParentOne { . . . class InnerChild extends ParentTwo { . . . / / can access both parents } }
  • 18. Introduction Multiple Inheritance Name Ambiguity Common Ancestors Inner Classes Summary References SUMMARY • In this chapter we have explored some of the problems that arise of the concept of multiple inheritance. • Name ambiguity. • Impact on substitution. • The Problem of Common Ancestors.
  • 19. Introduction Multiple Inheritance Name Ambiguity Common Ancestors Inner Classes Summary References REFERENCES • Images and content for developing these slides have been taken from the follwoing book with the permission of the author. • An Introduction to Object Oriented Programming, Timothy Budd. • This presentation is developed using Beamer: • Singapore, wolverine.