SlideShare a Scribd company logo
1 of 23
Download to read offline
Multiple Inheritance




Traditional (C++-like) implementation of multiple inheritance has several
issues:
      the diamond problem,




  Michal P´se (CTU in Prague)
          ıˇ                    Object Programming Lect. 5: Multiple Inheritance   October 26, 2010   2 / 11
Multiple Inheritance




Traditional (C++-like) implementation of multiple inheritance has several
issues:
      the diamond problem,
      name clashes,




  Michal P´se (CTU in Prague)
          ıˇ                    Object Programming Lect. 5: Multiple Inheritance   October 26, 2010   2 / 11
Multiple Inheritance




Traditional (C++-like) implementation of multiple inheritance has several
issues:
      the diamond problem,
      name clashes,
      glue code and




  Michal P´se (CTU in Prague)
          ıˇ                    Object Programming Lect. 5: Multiple Inheritance   October 26, 2010   2 / 11
Multiple Inheritance




Traditional (C++-like) implementation of multiple inheritance has several
issues:
      the diamond problem,
      name clashes,
      glue code and
      initialization order.




  Michal P´se (CTU in Prague)
          ıˇ                    Object Programming Lect. 5: Multiple Inheritance   October 26, 2010   2 / 11
The Diamond Problem




class    Foo     {...}
class    Bar     extends Foo {...}
class    Baz     extends Foo {...}
class    Qux     extends Bar, Baz {...}

How many instances of Foo should be in one instance of Qux?




 Michal P´se (CTU in Prague)
         ıˇ                    Object Programming Lect. 5: Multiple Inheritance   October 26, 2010   3 / 11
Name Clashes




class Foo { void bar() {...} }
class Baz { void bar() {...} }
class Qux extends Foo, Baz {...}

     Which of the two methods named bar gets called during execution of
     new Qux().bar()?




 Michal P´se (CTU in Prague)
         ıˇ                    Object Programming Lect. 5: Multiple Inheritance   October 26, 2010   4 / 11
Name Clashes




class Foo { void bar() {...} }
class Baz { void bar() {...} }
class Qux extends Foo, Baz {...}

     Which of the two methods named bar gets called during execution of
     new Qux().bar()?
     What if we need to keep both implementations of bar?




 Michal P´se (CTU in Prague)
         ıˇ                    Object Programming Lect. 5: Multiple Inheritance   October 26, 2010   4 / 11
Name Clashes




class Foo { void bar() {...} }
class Baz { void bar() {...} }
class Qux extends Foo, Baz {...}

     Which of the two methods named bar gets called during execution of
     new Qux().bar()?
     What if we need to keep both implementations of bar?
     Is it even type-safe to discard one of bar implementations? What
     about the Liskov substitution principle?




 Michal P´se (CTU in Prague)
         ıˇ                    Object Programming Lect. 5: Multiple Inheritance   October 26, 2010   4 / 11
Glue Code



class Foo {                                           class Qux {
  void bar() { baz(); }                                 void corge() {...}
  abstract void baz();                                }
}

class Grault extends Foo, Qux {
  void baz() { corge(); }
}

Grault.baz exists only to connect Foo.baz and Qux.corge.
In a simplified way, glue code can be thought of as an opposite problem to
name clashes.


  Michal P´se (CTU in Prague)
          ıˇ                    Object Programming Lect. 5: Multiple Inheritance   October 26, 2010   5 / 11
Initialization Order




In which order should we dispatch parent constructors when there are
circular dependencies?




  Michal P´se (CTU in Prague)
          ıˇ                    Object Programming Lect. 5: Multiple Inheritance   October 26, 2010   6 / 11
The Need for Multiple Inheritance




Do we even need multiple inheritance? Is it worth the trouble?
      Yes.




  Michal P´se (CTU in Prague)
          ıˇ                    Object Programming Lect. 5: Multiple Inheritance   October 26, 2010   7 / 11
The Need for Multiple Inheritance




Do we even need multiple inheritance? Is it worth the trouble?
      Yes.
      Units of reuse are smaller than units of instantiation. To
      compose a class, many smaller reusable chunks of code need to be
      composed together.




  Michal P´se (CTU in Prague)
          ıˇ                    Object Programming Lect. 5: Multiple Inheritance   October 26, 2010   7 / 11
The Need for Multiple Inheritance




Do we even need multiple inheritance? Is it worth the trouble?
      Yes.
      Units of reuse are smaller than units of instantiation. To
      compose a class, many smaller reusable chunks of code need to be
      composed together.
      The alternative is code duplication.




  Michal P´se (CTU in Prague)
          ıˇ                    Object Programming Lect. 5: Multiple Inheritance   October 26, 2010   7 / 11
Traits



A recent multiple inheritance model.

When inheriting, traits allow to
      create method aliases (to partially resolve name clashes and name
      mismatches),




  Michal P´se (CTU in Prague)
          ıˇ                    Object Programming Lect. 5: Multiple Inheritance   October 26, 2010   8 / 11
Traits



A recent multiple inheritance model.

When inheriting, traits allow to
      create method aliases (to partially resolve name clashes and name
      mismatches),
      drop methods (to get rid of unwanted functionality or to avoid the
      diamond problem) and




  Michal P´se (CTU in Prague)
          ıˇ                    Object Programming Lect. 5: Multiple Inheritance   October 26, 2010   8 / 11
Traits



A recent multiple inheritance model.

When inheriting, traits allow to
      create method aliases (to partially resolve name clashes and name
      mismatches),
      drop methods (to get rid of unwanted functionality or to avoid the
      diamond problem) and
      break the Liskov substitution principle (they do not imply
      subtyping and therefore subsumption is not an issue).




  Michal P´se (CTU in Prague)
          ıˇ                    Object Programming Lect. 5: Multiple Inheritance   October 26, 2010   8 / 11
Eiffel’s Multiple Inheritance




Eiffel approach:
      allow method renaming (name clashes can be resolved while
      sticking to the Liskov substitution principle) and




  Michal P´se (CTU in Prague)
          ıˇ                    Object Programming Lect. 5: Multiple Inheritance   October 26, 2010   9 / 11
Eiffel’s Multiple Inheritance




Eiffel approach:
      allow method renaming (name clashes can be resolved while
      sticking to the Liskov substitution principle) and
      utilize static type information to keep track of method renaming.




  Michal P´se (CTU in Prague)
          ıˇ                    Object Programming Lect. 5: Multiple Inheritance   October 26, 2010   9 / 11
CZ (Cubic Zirconia)




     Two kinds of inheritance hierarchies: extends and requires.




 Michal P´se (CTU in Prague)
         ıˇ                    Object Programming Lect. 5: Multiple Inheritance   October 26, 2010   10 / 11
CZ (Cubic Zirconia)




     Two kinds of inheritance hierarchies: extends and requires.
     Extends hierarchy can not contain cycles.




 Michal P´se (CTU in Prague)
         ıˇ                    Object Programming Lect. 5: Multiple Inheritance   October 26, 2010   10 / 11
CZ (Cubic Zirconia)




     Two kinds of inheritance hierarchies: extends and requires.
     Extends hierarchy can not contain cycles.
     Initialization is based on extends hierarchy.




 Michal P´se (CTU in Prague)
         ıˇ                    Object Programming Lect. 5: Multiple Inheritance   October 26, 2010   10 / 11
See



St´phane Ducasse, Oscar Nierstrasz, Nathanael Sch¨rli, Roel Wuyts, and
  e                                              a
Andrew P. Black. Traits: A mechanism for fine-grained reuse. ACM
Transanctions on Programming Languages and Systems 28, 2 (March
2006), 331–388. http://doi.acm.org/10.1145/1119479.1119483
Donna Malayeri and Jonathan Aldrich. CZ: multiple inheritance
without diamonds. In Proceeding of the 24th ACM SIGPLAN conference
on Object oriented programming systems languages and applications
(OOPSLA ’09). 21–40.
http://doi.acm.org/10.1145/1640089.1640092




 Michal P´se (CTU in Prague)
         ıˇ                    Object Programming Lect. 5: Multiple Inheritance   October 26, 2010   11 / 11

More Related Content

Viewers also liked

Multiple Inheritance
Multiple InheritanceMultiple Inheritance
Multiple Inheritanceadil raja
 
C++ Multiple Inheritance
C++ Multiple InheritanceC++ Multiple Inheritance
C++ Multiple Inheritanceharshaltambe
 
Inheritance in JAVA PPT
Inheritance  in JAVA PPTInheritance  in JAVA PPT
Inheritance in JAVA PPTPooja Jaiswal
 
Entity Relationship diagrams - ER diagrams
Entity Relationship diagrams - ER diagramsEntity Relationship diagrams - ER diagrams
Entity Relationship diagrams - ER diagramsmbedlabs Technosolutions
 
How To Use VLC.pdf
How To Use VLC.pdfHow To Use VLC.pdf
How To Use VLC.pdfnoniefer20
 
Multiple Inheritance For C++
Multiple Inheritance For C++Multiple Inheritance For C++
Multiple Inheritance For C++elliando dias
 
Entity Relationship Diagram Templates by Creately
Entity Relationship Diagram Templates by CreatelyEntity Relationship Diagram Templates by Creately
Entity Relationship Diagram Templates by CreatelyCreately
 
Inheritance in c++ ppt (Powerpoint) | inheritance in c++ ppt presentation | i...
Inheritance in c++ ppt (Powerpoint) | inheritance in c++ ppt presentation | i...Inheritance in c++ ppt (Powerpoint) | inheritance in c++ ppt presentation | i...
Inheritance in c++ ppt (Powerpoint) | inheritance in c++ ppt presentation | i...cprogrammings
 
Hospital Management System
Hospital Management SystemHospital Management System
Hospital Management SystemPranil Dukare
 
Library management system
Library management systemLibrary management system
Library management systemashu6
 
Data Flow Diagrams
Data Flow DiagramsData Flow Diagrams
Data Flow DiagramsSinhaa Yash
 
Library Management System
Library Management SystemLibrary Management System
Library Management SystemAditya Shah
 

Viewers also liked (16)

Multiple Inheritance
Multiple InheritanceMultiple Inheritance
Multiple Inheritance
 
C++ Multiple Inheritance
C++ Multiple InheritanceC++ Multiple Inheritance
C++ Multiple Inheritance
 
inheritance in C++
inheritance in C++inheritance in C++
inheritance in C++
 
Inheritance
InheritanceInheritance
Inheritance
 
Inheritance
InheritanceInheritance
Inheritance
 
Inheritance in JAVA PPT
Inheritance  in JAVA PPTInheritance  in JAVA PPT
Inheritance in JAVA PPT
 
Entity Relationship diagrams - ER diagrams
Entity Relationship diagrams - ER diagramsEntity Relationship diagrams - ER diagrams
Entity Relationship diagrams - ER diagrams
 
How To Use VLC.pdf
How To Use VLC.pdfHow To Use VLC.pdf
How To Use VLC.pdf
 
Data flow diagrams - DFD
Data flow diagrams - DFDData flow diagrams - DFD
Data flow diagrams - DFD
 
Multiple Inheritance For C++
Multiple Inheritance For C++Multiple Inheritance For C++
Multiple Inheritance For C++
 
Entity Relationship Diagram Templates by Creately
Entity Relationship Diagram Templates by CreatelyEntity Relationship Diagram Templates by Creately
Entity Relationship Diagram Templates by Creately
 
Inheritance in c++ ppt (Powerpoint) | inheritance in c++ ppt presentation | i...
Inheritance in c++ ppt (Powerpoint) | inheritance in c++ ppt presentation | i...Inheritance in c++ ppt (Powerpoint) | inheritance in c++ ppt presentation | i...
Inheritance in c++ ppt (Powerpoint) | inheritance in c++ ppt presentation | i...
 
Hospital Management System
Hospital Management SystemHospital Management System
Hospital Management System
 
Library management system
Library management systemLibrary management system
Library management system
 
Data Flow Diagrams
Data Flow DiagramsData Flow Diagrams
Data Flow Diagrams
 
Library Management System
Library Management SystemLibrary Management System
Library Management System
 

Similar to Multiple Inheritance

Progress in semantic mapping - NKOS
Progress in semantic mapping - NKOSProgress in semantic mapping - NKOS
Progress in semantic mapping - NKOSAntoine Isaac
 
Getty Vocabulary Program LOD: Ontologies and Semantic Representation
Getty Vocabulary Program LOD: Ontologies and Semantic RepresentationGetty Vocabulary Program LOD: Ontologies and Semantic Representation
Getty Vocabulary Program LOD: Ontologies and Semantic RepresentationVladimir Alexiev, PhD, PMP
 
2P-Kt: logic programming with objects & functions in Kotlin
2P-Kt: logic programming with objects & functions in Kotlin2P-Kt: logic programming with objects & functions in Kotlin
2P-Kt: logic programming with objects & functions in KotlinGiovanni Ciatto
 
Riak Core: Building Distributed Applications Without Shared State
Riak Core: Building Distributed Applications Without Shared StateRiak Core: Building Distributed Applications Without Shared State
Riak Core: Building Distributed Applications Without Shared StateRusty Klophaus
 
Merging Models with the Epsilon Merging Language - A Decade Later
Merging Models with the Epsilon Merging Language - A Decade LaterMerging Models with the Epsilon Merging Language - A Decade Later
Merging Models with the Epsilon Merging Language - A Decade LaterDimitris Kolovos
 
Divide and Conquer Semantic Web with Modular
Divide and Conquer Semantic Web with ModularDivide and Conquer Semantic Web with Modular
Divide and Conquer Semantic Web with ModularJie Bao
 
FOMI2017 - Reusing Domain Ontologies in Linked Building Data: the Case of Bui...
FOMI2017 - Reusing Domain Ontologies in Linked Building Data: the Case of Bui...FOMI2017 - Reusing Domain Ontologies in Linked Building Data: the Case of Bui...
FOMI2017 - Reusing Domain Ontologies in Linked Building Data: the Case of Bui...Pieter Pauwels
 
An Introduction to AceWiki
An Introduction to AceWikiAn Introduction to AceWiki
An Introduction to AceWikiTobias Kuhn
 
Changes and Bugs: Mining and Predicting Development Activities
Changes and Bugs: Mining and Predicting Development ActivitiesChanges and Bugs: Mining and Predicting Development Activities
Changes and Bugs: Mining and Predicting Development ActivitiesThomas Zimmermann
 
Future Programming Language
Future Programming LanguageFuture Programming Language
Future Programming LanguageYLTO
 
A Mathematical Approach to Ontology Authoring and Documentation
A Mathematical Approach to Ontology Authoring and DocumentationA Mathematical Approach to Ontology Authoring and Documentation
A Mathematical Approach to Ontology Authoring and DocumentationChristoph Lange
 
Traits: A New Language Feature for PHP?
Traits: A New Language Feature for PHP?Traits: A New Language Feature for PHP?
Traits: A New Language Feature for PHP?Stefan Marr
 
GATE, HLT and Machine Learning, Sheffield, July 2003
GATE, HLT and Machine Learning, Sheffield, July 2003GATE, HLT and Machine Learning, Sheffield, July 2003
GATE, HLT and Machine Learning, Sheffield, July 2003butest
 
Linked Open Data (LOD) part 1
Linked Open Data (LOD) part 1Linked Open Data (LOD) part 1
Linked Open Data (LOD) part 1IPLODProject
 
BestPortal: Lessons Learned in Lightweight Semantic Access to Court Proceedings
BestPortal: Lessons Learned in Lightweight Semantic Access to Court ProceedingsBestPortal: Lessons Learned in Lightweight Semantic Access to Court Proceedings
BestPortal: Lessons Learned in Lightweight Semantic Access to Court ProceedingsRinke Hoekstra
 
DCMI Keynote: Bridging the Semantic Gaps and Interoperability
DCMI Keynote: Bridging the Semantic Gaps and InteroperabilityDCMI Keynote: Bridging the Semantic Gaps and Interoperability
DCMI Keynote: Bridging the Semantic Gaps and InteroperabilityMike Bergman
 
A N E XTENSION OF P ROTÉGÉ FOR AN AUTOMA TIC F UZZY - O NTOLOGY BUILDING U...
A N  E XTENSION OF  P ROTÉGÉ FOR AN AUTOMA TIC  F UZZY - O NTOLOGY BUILDING U...A N  E XTENSION OF  P ROTÉGÉ FOR AN AUTOMA TIC  F UZZY - O NTOLOGY BUILDING U...
A N E XTENSION OF P ROTÉGÉ FOR AN AUTOMA TIC F UZZY - O NTOLOGY BUILDING U...ijcsit
 

Similar to Multiple Inheritance (20)

Progress in semantic mapping - NKOS
Progress in semantic mapping - NKOSProgress in semantic mapping - NKOS
Progress in semantic mapping - NKOS
 
Getty Vocabulary Program LOD: Ontologies and Semantic Representation
Getty Vocabulary Program LOD: Ontologies and Semantic RepresentationGetty Vocabulary Program LOD: Ontologies and Semantic Representation
Getty Vocabulary Program LOD: Ontologies and Semantic Representation
 
CORBA
CORBACORBA
CORBA
 
2P-Kt: logic programming with objects & functions in Kotlin
2P-Kt: logic programming with objects & functions in Kotlin2P-Kt: logic programming with objects & functions in Kotlin
2P-Kt: logic programming with objects & functions in Kotlin
 
Riak Core: Building Distributed Applications Without Shared State
Riak Core: Building Distributed Applications Without Shared StateRiak Core: Building Distributed Applications Without Shared State
Riak Core: Building Distributed Applications Without Shared State
 
Merging Models with the Epsilon Merging Language - A Decade Later
Merging Models with the Epsilon Merging Language - A Decade LaterMerging Models with the Epsilon Merging Language - A Decade Later
Merging Models with the Epsilon Merging Language - A Decade Later
 
Divide and Conquer Semantic Web with Modular
Divide and Conquer Semantic Web with ModularDivide and Conquer Semantic Web with Modular
Divide and Conquer Semantic Web with Modular
 
FOMI2017 - Reusing Domain Ontologies in Linked Building Data: the Case of Bui...
FOMI2017 - Reusing Domain Ontologies in Linked Building Data: the Case of Bui...FOMI2017 - Reusing Domain Ontologies in Linked Building Data: the Case of Bui...
FOMI2017 - Reusing Domain Ontologies in Linked Building Data: the Case of Bui...
 
An Introduction to AceWiki
An Introduction to AceWikiAn Introduction to AceWiki
An Introduction to AceWiki
 
Reclassification
ReclassificationReclassification
Reclassification
 
Changes and Bugs: Mining and Predicting Development Activities
Changes and Bugs: Mining and Predicting Development ActivitiesChanges and Bugs: Mining and Predicting Development Activities
Changes and Bugs: Mining and Predicting Development Activities
 
Future Programming Language
Future Programming LanguageFuture Programming Language
Future Programming Language
 
Mocking the unmockable with Moles
Mocking the unmockable with MolesMocking the unmockable with Moles
Mocking the unmockable with Moles
 
A Mathematical Approach to Ontology Authoring and Documentation
A Mathematical Approach to Ontology Authoring and DocumentationA Mathematical Approach to Ontology Authoring and Documentation
A Mathematical Approach to Ontology Authoring and Documentation
 
Traits: A New Language Feature for PHP?
Traits: A New Language Feature for PHP?Traits: A New Language Feature for PHP?
Traits: A New Language Feature for PHP?
 
GATE, HLT and Machine Learning, Sheffield, July 2003
GATE, HLT and Machine Learning, Sheffield, July 2003GATE, HLT and Machine Learning, Sheffield, July 2003
GATE, HLT and Machine Learning, Sheffield, July 2003
 
Linked Open Data (LOD) part 1
Linked Open Data (LOD) part 1Linked Open Data (LOD) part 1
Linked Open Data (LOD) part 1
 
BestPortal: Lessons Learned in Lightweight Semantic Access to Court Proceedings
BestPortal: Lessons Learned in Lightweight Semantic Access to Court ProceedingsBestPortal: Lessons Learned in Lightweight Semantic Access to Court Proceedings
BestPortal: Lessons Learned in Lightweight Semantic Access to Court Proceedings
 
DCMI Keynote: Bridging the Semantic Gaps and Interoperability
DCMI Keynote: Bridging the Semantic Gaps and InteroperabilityDCMI Keynote: Bridging the Semantic Gaps and Interoperability
DCMI Keynote: Bridging the Semantic Gaps and Interoperability
 
A N E XTENSION OF P ROTÉGÉ FOR AN AUTOMA TIC F UZZY - O NTOLOGY BUILDING U...
A N  E XTENSION OF  P ROTÉGÉ FOR AN AUTOMA TIC  F UZZY - O NTOLOGY BUILDING U...A N  E XTENSION OF  P ROTÉGÉ FOR AN AUTOMA TIC  F UZZY - O NTOLOGY BUILDING U...
A N E XTENSION OF P ROTÉGÉ FOR AN AUTOMA TIC F UZZY - O NTOLOGY BUILDING U...
 

Multiple Inheritance

  • 1.
  • 2. Multiple Inheritance Traditional (C++-like) implementation of multiple inheritance has several issues: the diamond problem, Michal P´se (CTU in Prague) ıˇ Object Programming Lect. 5: Multiple Inheritance October 26, 2010 2 / 11
  • 3. Multiple Inheritance Traditional (C++-like) implementation of multiple inheritance has several issues: the diamond problem, name clashes, Michal P´se (CTU in Prague) ıˇ Object Programming Lect. 5: Multiple Inheritance October 26, 2010 2 / 11
  • 4. Multiple Inheritance Traditional (C++-like) implementation of multiple inheritance has several issues: the diamond problem, name clashes, glue code and Michal P´se (CTU in Prague) ıˇ Object Programming Lect. 5: Multiple Inheritance October 26, 2010 2 / 11
  • 5. Multiple Inheritance Traditional (C++-like) implementation of multiple inheritance has several issues: the diamond problem, name clashes, glue code and initialization order. Michal P´se (CTU in Prague) ıˇ Object Programming Lect. 5: Multiple Inheritance October 26, 2010 2 / 11
  • 6. The Diamond Problem class Foo {...} class Bar extends Foo {...} class Baz extends Foo {...} class Qux extends Bar, Baz {...} How many instances of Foo should be in one instance of Qux? Michal P´se (CTU in Prague) ıˇ Object Programming Lect. 5: Multiple Inheritance October 26, 2010 3 / 11
  • 7. Name Clashes class Foo { void bar() {...} } class Baz { void bar() {...} } class Qux extends Foo, Baz {...} Which of the two methods named bar gets called during execution of new Qux().bar()? Michal P´se (CTU in Prague) ıˇ Object Programming Lect. 5: Multiple Inheritance October 26, 2010 4 / 11
  • 8. Name Clashes class Foo { void bar() {...} } class Baz { void bar() {...} } class Qux extends Foo, Baz {...} Which of the two methods named bar gets called during execution of new Qux().bar()? What if we need to keep both implementations of bar? Michal P´se (CTU in Prague) ıˇ Object Programming Lect. 5: Multiple Inheritance October 26, 2010 4 / 11
  • 9. Name Clashes class Foo { void bar() {...} } class Baz { void bar() {...} } class Qux extends Foo, Baz {...} Which of the two methods named bar gets called during execution of new Qux().bar()? What if we need to keep both implementations of bar? Is it even type-safe to discard one of bar implementations? What about the Liskov substitution principle? Michal P´se (CTU in Prague) ıˇ Object Programming Lect. 5: Multiple Inheritance October 26, 2010 4 / 11
  • 10. Glue Code class Foo { class Qux { void bar() { baz(); } void corge() {...} abstract void baz(); } } class Grault extends Foo, Qux { void baz() { corge(); } } Grault.baz exists only to connect Foo.baz and Qux.corge. In a simplified way, glue code can be thought of as an opposite problem to name clashes. Michal P´se (CTU in Prague) ıˇ Object Programming Lect. 5: Multiple Inheritance October 26, 2010 5 / 11
  • 11. Initialization Order In which order should we dispatch parent constructors when there are circular dependencies? Michal P´se (CTU in Prague) ıˇ Object Programming Lect. 5: Multiple Inheritance October 26, 2010 6 / 11
  • 12. The Need for Multiple Inheritance Do we even need multiple inheritance? Is it worth the trouble? Yes. Michal P´se (CTU in Prague) ıˇ Object Programming Lect. 5: Multiple Inheritance October 26, 2010 7 / 11
  • 13. The Need for Multiple Inheritance Do we even need multiple inheritance? Is it worth the trouble? Yes. Units of reuse are smaller than units of instantiation. To compose a class, many smaller reusable chunks of code need to be composed together. Michal P´se (CTU in Prague) ıˇ Object Programming Lect. 5: Multiple Inheritance October 26, 2010 7 / 11
  • 14. The Need for Multiple Inheritance Do we even need multiple inheritance? Is it worth the trouble? Yes. Units of reuse are smaller than units of instantiation. To compose a class, many smaller reusable chunks of code need to be composed together. The alternative is code duplication. Michal P´se (CTU in Prague) ıˇ Object Programming Lect. 5: Multiple Inheritance October 26, 2010 7 / 11
  • 15. Traits A recent multiple inheritance model. When inheriting, traits allow to create method aliases (to partially resolve name clashes and name mismatches), Michal P´se (CTU in Prague) ıˇ Object Programming Lect. 5: Multiple Inheritance October 26, 2010 8 / 11
  • 16. Traits A recent multiple inheritance model. When inheriting, traits allow to create method aliases (to partially resolve name clashes and name mismatches), drop methods (to get rid of unwanted functionality or to avoid the diamond problem) and Michal P´se (CTU in Prague) ıˇ Object Programming Lect. 5: Multiple Inheritance October 26, 2010 8 / 11
  • 17. Traits A recent multiple inheritance model. When inheriting, traits allow to create method aliases (to partially resolve name clashes and name mismatches), drop methods (to get rid of unwanted functionality or to avoid the diamond problem) and break the Liskov substitution principle (they do not imply subtyping and therefore subsumption is not an issue). Michal P´se (CTU in Prague) ıˇ Object Programming Lect. 5: Multiple Inheritance October 26, 2010 8 / 11
  • 18. Eiffel’s Multiple Inheritance Eiffel approach: allow method renaming (name clashes can be resolved while sticking to the Liskov substitution principle) and Michal P´se (CTU in Prague) ıˇ Object Programming Lect. 5: Multiple Inheritance October 26, 2010 9 / 11
  • 19. Eiffel’s Multiple Inheritance Eiffel approach: allow method renaming (name clashes can be resolved while sticking to the Liskov substitution principle) and utilize static type information to keep track of method renaming. Michal P´se (CTU in Prague) ıˇ Object Programming Lect. 5: Multiple Inheritance October 26, 2010 9 / 11
  • 20. CZ (Cubic Zirconia) Two kinds of inheritance hierarchies: extends and requires. Michal P´se (CTU in Prague) ıˇ Object Programming Lect. 5: Multiple Inheritance October 26, 2010 10 / 11
  • 21. CZ (Cubic Zirconia) Two kinds of inheritance hierarchies: extends and requires. Extends hierarchy can not contain cycles. Michal P´se (CTU in Prague) ıˇ Object Programming Lect. 5: Multiple Inheritance October 26, 2010 10 / 11
  • 22. CZ (Cubic Zirconia) Two kinds of inheritance hierarchies: extends and requires. Extends hierarchy can not contain cycles. Initialization is based on extends hierarchy. Michal P´se (CTU in Prague) ıˇ Object Programming Lect. 5: Multiple Inheritance October 26, 2010 10 / 11
  • 23. See St´phane Ducasse, Oscar Nierstrasz, Nathanael Sch¨rli, Roel Wuyts, and e a Andrew P. Black. Traits: A mechanism for fine-grained reuse. ACM Transanctions on Programming Languages and Systems 28, 2 (March 2006), 331–388. http://doi.acm.org/10.1145/1119479.1119483 Donna Malayeri and Jonathan Aldrich. CZ: multiple inheritance without diamonds. In Proceeding of the 24th ACM SIGPLAN conference on Object oriented programming systems languages and applications (OOPSLA ’09). 21–40. http://doi.acm.org/10.1145/1640089.1640092 Michal P´se (CTU in Prague) ıˇ Object Programming Lect. 5: Multiple Inheritance October 26, 2010 11 / 11