SlideShare a Scribd company logo
Engr 691
Engr 691
Special Topics in Engineering Science
Special Topics in Engineering Science
Software Architecture
Software Architecture
Spring Semester 2004
Spring Semester 2004
Lecture Notes
Lecture Notes
Multiple Inheritance
Multiple Inheritance
This Web document was based on a set of slides created by the
This Web document was based on a set of slides created by the
instructor for use in the Fall 1997 and Spring 1999 offerings of the
instructor for use in the Fall 1997 and Spring 1999 offerings of the
object-oriented design and programming course.
object-oriented design and programming course.
That set was, in turn, based on a set of slides created by Timothy
That set was, in turn, based on a set of slides created by Timothy
Budd to supplement chapter 13 of his textbook
Budd to supplement chapter 13 of his textbook
An Introduction to Object-Oriented Programming
An Introduction to Object-Oriented Programming, Second Edition
, Second Edition
(Addison-Wesley, 1997)
(Addison-Wesley, 1997)
Orthogonal Classifications
Orthogonal Classifications
Objects often characterized in different ways that are
Objects often characterized in different ways that are
orthogonal to each other
orthogonal to each other
For example, the instructor is
For example, the instructor is
 North American
North American
 Male
Male
 Professor
Professor
 Computer scientist
Computer scientist
None of these are proper subsets of each other
None of these are proper subsets of each other
Cannot be placed into an inheritance hierarchy
Cannot be placed into an inheritance hierarchy
CS Example: Complex Numbers
CS Example: Complex Numbers
Two abstract classifications:
Two abstract classifications:
 Magnitude
Magnitude:
:
 things that can be compared to each other
things that can be compared to each other
 Number
Number:
:
 things that can perform arithmetic
things that can perform arithmetic
Three specific classes:
Three specific classes:
 Integer
Integer:
:
 comparable and arithmetic
comparable and arithmetic
 Char
Char:
:
 comparable but not arithmetic
comparable but not arithmetic
 Complex
Complex:
:
 arithmetic but not comparable
arithmetic but not comparable
Solutions
Solutions
1.
1. Make
Make Number
Number subclass of
subclass of Magnitude
Magnitude, but redefine
, but redefine
comparison operators in class
comparison operators in class Complex
Complex to print error
to print error
message –
message – subclassing for limitation
subclassing for limitation
2.
2. Don't use inheritance at all, redefine all operators in all classes
Don't use inheritance at all, redefine all operators in all classes
–
– flattening the inheritance tree
flattening the inheritance tree
3.
3. Use inheritance for some relationships, but simulate others
Use inheritance for some relationships, but simulate others
– use
– use Number
Number, but each number implements all relational
, but each number implements all relational
operators
operators
4.
4. Make
Make Number
Number and
and Magnitude
Magnitude independent, and have
independent, and have
Integer inherit from both –
Integer inherit from both – multiple inheritance
multiple inheritance
Inheritance as a Form of
Inheritance as a Form of
Combination
Combination
____ Char
____ Char
____|
____|
|
|
Magnitude <--|
Magnitude <--|
|
|
|____
|____
|____
|____
____ Integer
____ Integer
____|
____|
|
|
Number <--|
Number <--|
|
|
|____
|____
|____ Complex
|____ Complex
Another Example:
Another Example:
Cascading Menus
Cascading Menus
A
A Menu
Menu is structure charged with displaying itself when
is structure charged with displaying itself when
selected by users
selected by users
A
A Menu
Menu maintains collection of
maintains collection of MenuItem
MenuItems
s
Each
Each MenuItem
MenuItem knows how to respond when selected
knows how to respond when selected
A
A cascading menu
cascading menu is both a
is both a MenuItem
MenuItem and
and Menu
Menu
Multiple Inheritance:
Multiple Inheritance:
Name Ambiguity Problem
Name Ambiguity Problem
What happens when same name used in both
What happens when same name used in both
parent classes?
parent classes?
A
A CardDeck
CardDeck knows how to
knows how to draw
draw (select) a
(select) a Card
Card
A
A GraphicalItem
GraphicalItem knows how to
knows how to draw
draw (display)
(display)
an image on screen
an image on screen
A
A GraphicalCardDeck
GraphicalCardDeck should be able to draw –
should be able to draw –
but which?
but which?
Multiple Inheritance:
Multiple Inheritance:
Common Ancestors?
Common Ancestors?
What happens when parent classes have common root ancestor?
What happens when parent classes have common root ancestor?
Does new object have one or two instances of common ancestor?
Does new object have one or two instances of common ancestor?
____ InStream ____
____ InStream ____
____| |____
____| |____
| |
| |
Stream <--| |<-- InOutStream
Stream <--| |<-- InOutStream
|____ ____|
|____ ____|
|____ OutStream ____|
|____ OutStream ____|
Multiple Inheritance in Java
Multiple Inheritance in Java
Java supports multiple inheritance of interfaces
Java supports multiple inheritance of interfaces
(subtypes) but not of classes (subclasses)
(subtypes) but not of classes (subclasses)
interface A { ... }
interface A { ... }
interface B { ... }
interface B { ... }
interface AB extends A, B { ... }
interface AB extends A, B { ... }
interface C { ... }
interface C { ... }
class X { ... }
class X { ... }
class Y extends X implements AB, C { ... }
class Y extends X implements AB, C { ... }

More Related Content

PDF
Multiple Inheritance
PPTX
Object Oriented Design and Programming Unit-03
PPT
10.Inheritance.ppt for oops programinggg
PPTX
Introduction to inheritance and different types of inheritance
PPTX
Multiple inheritance
PPT
PPTX
Inheritance
DOC
How would you implement multiple inheritance in java
Multiple Inheritance
Object Oriented Design and Programming Unit-03
10.Inheritance.ppt for oops programinggg
Introduction to inheritance and different types of inheritance
Multiple inheritance
Inheritance
How would you implement multiple inheritance in java

Similar to Multiple Inheritance powerpoint presentation (20)

PPTX
inheritance in OOPM
PDF
c++Inheritance.pdf
PPTX
inheritance in C++
PPTX
2.6 Types of Inheritance in OOP C++.pptx
PPTX
#OOP_D_ITS - 6th - C++ Oop Inheritance
PPTX
Object Oriented Programming using C++: Ch09 Inheritance.pptx
PDF
OOP Assign No.03(AP).pdf
PPTX
2CPP07 - Inheritance
PPTX
inheriTANCE IN OBJECT ORIENTED PROGRAM.pptx
PPSX
Inheritance and Polymorphism in Oops
PPTX
Aryan's pres. entation.pptx
PPTX
Inheritance
PPTX
Ritik (inheritance.cpp)
PDF
Unit 3 notes.pdf
PPTX
Lecture 3
PPTX
Inheritance
PPTX
Multiple Inheritance
PPTX
Inheritance.pptx
PDF
C++ Multiple Inheritance
PDF
OOP Inheritance
inheritance in OOPM
c++Inheritance.pdf
inheritance in C++
2.6 Types of Inheritance in OOP C++.pptx
#OOP_D_ITS - 6th - C++ Oop Inheritance
Object Oriented Programming using C++: Ch09 Inheritance.pptx
OOP Assign No.03(AP).pdf
2CPP07 - Inheritance
inheriTANCE IN OBJECT ORIENTED PROGRAM.pptx
Inheritance and Polymorphism in Oops
Aryan's pres. entation.pptx
Inheritance
Ritik (inheritance.cpp)
Unit 3 notes.pdf
Lecture 3
Inheritance
Multiple Inheritance
Inheritance.pptx
C++ Multiple Inheritance
OOP Inheritance
Ad

Recently uploaded (20)

PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PPTX
Lesson notes of climatology university.
PDF
TR - Agricultural Crops Production NC III.pdf
PPTX
Cell Structure & Organelles in detailed.
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
Basic Mud Logging Guide for educational purpose
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PPTX
master seminar digital applications in india
PDF
Sports Quiz easy sports quiz sports quiz
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PDF
Complications of Minimal Access Surgery at WLH
PPTX
GDM (1) (1).pptx small presentation for students
PDF
01-Introduction-to-Information-Management.pdf
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
Computing-Curriculum for Schools in Ghana
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
2.FourierTransform-ShortQuestionswithAnswers.pdf
Lesson notes of climatology university.
TR - Agricultural Crops Production NC III.pdf
Cell Structure & Organelles in detailed.
STATICS OF THE RIGID BODIES Hibbelers.pdf
Microbial diseases, their pathogenesis and prophylaxis
Basic Mud Logging Guide for educational purpose
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
master seminar digital applications in india
Sports Quiz easy sports quiz sports quiz
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
Complications of Minimal Access Surgery at WLH
GDM (1) (1).pptx small presentation for students
01-Introduction-to-Information-Management.pdf
Final Presentation General Medicine 03-08-2024.pptx
Computing-Curriculum for Schools in Ghana
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Ad

Multiple Inheritance powerpoint presentation

  • 1. Engr 691 Engr 691 Special Topics in Engineering Science Special Topics in Engineering Science Software Architecture Software Architecture Spring Semester 2004 Spring Semester 2004 Lecture Notes Lecture Notes
  • 2. Multiple Inheritance Multiple Inheritance This Web document was based on a set of slides created by the This Web document was based on a set of slides created by the instructor for use in the Fall 1997 and Spring 1999 offerings of the instructor for use in the Fall 1997 and Spring 1999 offerings of the object-oriented design and programming course. object-oriented design and programming course. That set was, in turn, based on a set of slides created by Timothy That set was, in turn, based on a set of slides created by Timothy Budd to supplement chapter 13 of his textbook Budd to supplement chapter 13 of his textbook An Introduction to Object-Oriented Programming An Introduction to Object-Oriented Programming, Second Edition , Second Edition (Addison-Wesley, 1997) (Addison-Wesley, 1997)
  • 3. Orthogonal Classifications Orthogonal Classifications Objects often characterized in different ways that are Objects often characterized in different ways that are orthogonal to each other orthogonal to each other For example, the instructor is For example, the instructor is  North American North American  Male Male  Professor Professor  Computer scientist Computer scientist None of these are proper subsets of each other None of these are proper subsets of each other Cannot be placed into an inheritance hierarchy Cannot be placed into an inheritance hierarchy
  • 4. CS Example: Complex Numbers CS Example: Complex Numbers Two abstract classifications: Two abstract classifications:  Magnitude Magnitude: :  things that can be compared to each other things that can be compared to each other  Number Number: :  things that can perform arithmetic things that can perform arithmetic Three specific classes: Three specific classes:  Integer Integer: :  comparable and arithmetic comparable and arithmetic  Char Char: :  comparable but not arithmetic comparable but not arithmetic  Complex Complex: :  arithmetic but not comparable arithmetic but not comparable
  • 5. Solutions Solutions 1. 1. Make Make Number Number subclass of subclass of Magnitude Magnitude, but redefine , but redefine comparison operators in class comparison operators in class Complex Complex to print error to print error message – message – subclassing for limitation subclassing for limitation 2. 2. Don't use inheritance at all, redefine all operators in all classes Don't use inheritance at all, redefine all operators in all classes – – flattening the inheritance tree flattening the inheritance tree 3. 3. Use inheritance for some relationships, but simulate others Use inheritance for some relationships, but simulate others – use – use Number Number, but each number implements all relational , but each number implements all relational operators operators 4. 4. Make Make Number Number and and Magnitude Magnitude independent, and have independent, and have Integer inherit from both – Integer inherit from both – multiple inheritance multiple inheritance
  • 6. Inheritance as a Form of Inheritance as a Form of Combination Combination ____ Char ____ Char ____| ____| | | Magnitude <--| Magnitude <--| | | |____ |____ |____ |____ ____ Integer ____ Integer ____| ____| | | Number <--| Number <--| | | |____ |____ |____ Complex |____ Complex
  • 7. Another Example: Another Example: Cascading Menus Cascading Menus A A Menu Menu is structure charged with displaying itself when is structure charged with displaying itself when selected by users selected by users A A Menu Menu maintains collection of maintains collection of MenuItem MenuItems s Each Each MenuItem MenuItem knows how to respond when selected knows how to respond when selected A A cascading menu cascading menu is both a is both a MenuItem MenuItem and and Menu Menu
  • 8. Multiple Inheritance: Multiple Inheritance: Name Ambiguity Problem Name Ambiguity Problem What happens when same name used in both What happens when same name used in both parent classes? parent classes? A A CardDeck CardDeck knows how to knows how to draw draw (select) a (select) a Card Card A A GraphicalItem GraphicalItem knows how to knows how to draw draw (display) (display) an image on screen an image on screen A A GraphicalCardDeck GraphicalCardDeck should be able to draw – should be able to draw – but which? but which?
  • 9. Multiple Inheritance: Multiple Inheritance: Common Ancestors? Common Ancestors? What happens when parent classes have common root ancestor? What happens when parent classes have common root ancestor? Does new object have one or two instances of common ancestor? Does new object have one or two instances of common ancestor? ____ InStream ____ ____ InStream ____ ____| |____ ____| |____ | | | | Stream <--| |<-- InOutStream Stream <--| |<-- InOutStream |____ ____| |____ ____| |____ OutStream ____| |____ OutStream ____|
  • 10. Multiple Inheritance in Java Multiple Inheritance in Java Java supports multiple inheritance of interfaces Java supports multiple inheritance of interfaces (subtypes) but not of classes (subclasses) (subtypes) but not of classes (subclasses) interface A { ... } interface A { ... } interface B { ... } interface B { ... } interface AB extends A, B { ... } interface AB extends A, B { ... } interface C { ... } interface C { ... } class X { ... } class X { ... } class Y extends X implements AB, C { ... } class Y extends X implements AB, C { ... }