SlideShare a Scribd company logo
1 of 25
Download to read offline
What Is Subclassing?




Subclassing is a process in which a new class is derived from an old one. It
is a distinct concept from
      (subtype) polymorphism,
      generalization/specialization and
      composition.




  Michal P´se (CTU in Prague)
          ıˇ                    Object Programming Lect. 4: Inheritance   October 19, 2010   2 / 12
Subclassing = Subtyping




     Subtypes are not required to share any code with their supertypes.




 Michal P´se (CTU in Prague)
         ıˇ                    Object Programming Lect. 4: Inheritance   October 19, 2010   3 / 12
Subclassing = Subtyping




     Subtypes are not required to share any code with their supertypes.
     On the other hand, subtypes are required to stick to the contract of
     their supertype (the Liskov substition principle).




 Michal P´se (CTU in Prague)
         ıˇ                    Object Programming Lect. 4: Inheritance   October 19, 2010   3 / 12
Subclassing = Subtyping




     Subtypes are not required to share any code with their supertypes.
     On the other hand, subtypes are required to stick to the contract of
     their supertype (the Liskov substition principle).
Subtyping only concerns behavior, subclassing only concerns code.




 Michal P´se (CTU in Prague)
         ıˇ                    Object Programming Lect. 4: Inheritance   October 19, 2010   3 / 12
The Fallacy of Current Industrial Programming Languages




In Java (and many other languages)
      subclassing implies subtyping, in other words,
      every subclass has to stick to the contract of its parent class.
That severly limits possible code reuse!




  Michal P´se (CTU in Prague)
          ıˇ                    Object Programming Lect. 4: Inheritance   October 19, 2010   4 / 12
Example




void DFS(Node n) {
  addToStack( n);
  while ( stackNotEmpty()) {
    n = removeFromStack();
    processNode( n);
    for ( Node c: n.children())
      addToStack( c);
  }
}




  Michal P´se (CTU in Prague)
          ıˇ                    Object Programming Lect. 4: Inheritance   October 19, 2010   5 / 12
Example




                                                                  Obviously, addToStack
void DFS(Node n) {
                                                                  inserts a node at the
  addToStack( n);
                                                                  beginning of a list and
  while ( stackNotEmpty()) {
                                                                  removeFromStack removes
    n = removeFromStack();
                                                                  a node from the beginning
    processNode( n);
                                                                  of that list.
    for ( Node c: n.children())
      addToStack( c);
  }
}




  Michal P´se (CTU in Prague)
          ıˇ                    Object Programming Lect. 4: Inheritance     October 19, 2010   5 / 12
Example




                                                                  Obviously, addToStack
void DFS(Node n) {
                                                                  inserts a node at the
  addToStack( n);
                                                                  beginning of a list and
  while ( stackNotEmpty()) {
                                                                  removeFromStack removes
    n = removeFromStack();
                                                                  a node from the beginning
    processNode( n);
                                                                  of that list.
    for ( Node c: n.children())
      addToStack( c);                                             Is it correct to override
  }                                                               addToStack to insert a
}                                                                 node at the end of the list?




  Michal P´se (CTU in Prague)
          ıˇ                    Object Programming Lect. 4: Inheritance       October 19, 2010   5 / 12
Example (II)




     Not in Java—the new subtype would break the contract of the
     supertype.




 Michal P´se (CTU in Prague)
         ıˇ                    Object Programming Lect. 4: Inheritance   October 19, 2010   6 / 12
Example (II)




     Not in Java—the new subtype would break the contract of the
     supertype.
     However, it is perfectly legitimate in languages where subclassing
     does not imply subtyping—the new class simply isn’t type-compatible
     with the old one.




 Michal P´se (CTU in Prague)
         ıˇ                    Object Programming Lect. 4: Inheritance   October 19, 2010   6 / 12
Subclassing = Specialization




     Subclassing does not imply specialization—subclass does not have to
     be a specialized version of superclass.




 Michal P´se (CTU in Prague)
         ıˇ                    Object Programming Lect. 4: Inheritance   October 19, 2010   7 / 12
Subclassing = Specialization




     Subclassing does not imply specialization—subclass does not have to
     be a specialized version of superclass.
     Specialization does not imply subclassing—a specialized version of
     object does not have to share code with the base case.




 Michal P´se (CTU in Prague)
         ıˇ                    Object Programming Lect. 4: Inheritance   October 19, 2010   7 / 12
Subclassing = Specialization




     Subclassing does not imply specialization—subclass does not have to
     be a specialized version of superclass.
     Specialization does not imply subclassing—a specialized version of
     object does not have to share code with the base case.
     In fact, subtyping and specialization are distinct notions as well.




 Michal P´se (CTU in Prague)
         ıˇ                    Object Programming Lect. 4: Inheritance   October 19, 2010   7 / 12
Subclassing = Composition




     Subclassing and composition both facilitate code reuse.
     Is there anything that can be achieved by subclassing and not
     achieved by composition or vice versa?




 Michal P´se (CTU in Prague)
         ıˇ                    Object Programming Lect. 4: Inheritance   October 19, 2010   8 / 12
Poor Man’s Inheritance



class Foo {                                         class Qux {
  void bar() {...}                                    Foo foo = new Foo();
  int baz() {...}                                     void bar() {
}                                                       foo.bar();
                                                      }

                                                        int baz() {
                                                          return foo.baz();
                                                        }
                                                    }




  Michal P´se (CTU in Prague)
          ıˇ                    Object Programming Lect. 4: Inheritance   October 19, 2010   9 / 12
Poor Man’s Inheritance



class Foo {                                         class Qux {
  void bar() {...}                                    Foo foo = new Foo();
  int baz() {...}                                     void bar() {
}                                                       foo.bar();
                                                      }

                                                        int baz() {
                                                          return foo.baz();
                                                        }
                                                    }

Emulation of inheritance using composition is far from perfect—method
overriding can be emulated only in the simplest cases.

  Michal P´se (CTU in Prague)
          ıˇ                    Object Programming Lect. 4: Inheritance   October 19, 2010   9 / 12
The Essence of Inheritance




So what exactly is inheritance?




  Michal P´se (CTU in Prague)
          ıˇ                    Object Programming Lect. 4: Inheritance   October 19, 2010   10 / 12
The Essence of Inheritance




So what exactly is inheritance?
      Inheritance is a mechanism facilitating code reuse.




  Michal P´se (CTU in Prague)
          ıˇ                    Object Programming Lect. 4: Inheritance   October 19, 2010   10 / 12
The Essence of Inheritance




So what exactly is inheritance?
      Inheritance is a mechanism facilitating code reuse.
      It can be thought about as the C-style include with overriding.




  Michal P´se (CTU in Prague)
          ıˇ                    Object Programming Lect. 4: Inheritance   October 19, 2010   10 / 12
The Essence of Inheritance




So what exactly is inheritance?
      Inheritance is a mechanism facilitating code reuse.
      It can be thought about as the C-style include with overriding.
      It enables reuse even in ways the original code creator never imagined.




  Michal P´se (CTU in Prague)
          ıˇ                    Object Programming Lect. 4: Inheritance   October 19, 2010   10 / 12
Implementation of Inheritance




     C++: virtual methods table.




 Michal P´se (CTU in Prague)
         ıˇ                    Object Programming Lect. 4: Inheritance   October 19, 2010   11 / 12
Implementation of Inheritance




     C++: virtual methods table.
     In Smalltalk: method dictionary.




 Michal P´se (CTU in Prague)
         ıˇ                    Object Programming Lect. 4: Inheritance   October 19, 2010   11 / 12
Implementation of Inheritance




     C++: virtual methods table.
     In Smalltalk: method dictionary.
     In systems with runtime: inline cache.




 Michal P´se (CTU in Prague)
         ıˇ                    Object Programming Lect. 4: Inheritance   October 19, 2010   11 / 12
See




Taivalsaari, A. On the notion of inheritance. ACM Computing Surveys
28, 3 (Sep. 1996), 438–479.
http://doi.acm.org/10.1145/243439.243441




 Michal P´se (CTU in Prague)
         ıˇ                    Object Programming Lect. 4: Inheritance   October 19, 2010   12 / 12

More Related Content

Similar to Inheritance

Similar to Inheritance (6)

Multiple Dispatch
Multiple DispatchMultiple Dispatch
Multiple Dispatch
 
Subtyping
SubtypingSubtyping
Subtyping
 
Sour Pickles
Sour PicklesSour Pickles
Sour Pickles
 
Stack
StackStack
Stack
 
Type Systems
Type SystemsType Systems
Type Systems
 
Stack
StackStack
Stack
 

More from Michal Píše

More from Michal Píše (7)

Prototype Languages
Prototype LanguagesPrototype Languages
Prototype Languages
 
Reflection and Metadata
Reflection and MetadataReflection and Metadata
Reflection and Metadata
 
Encapsulation
EncapsulationEncapsulation
Encapsulation
 
Garbage Collection
Garbage CollectionGarbage Collection
Garbage Collection
 
Flow Control
Flow ControlFlow Control
Flow Control
 
Reclassification
ReclassificationReclassification
Reclassification
 
Functional Concepts
Functional ConceptsFunctional Concepts
Functional Concepts
 

Recently uploaded

Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...Pooja Nehwal
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...anjaliyadav012327
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 

Recently uploaded (20)

Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 

Inheritance

  • 1.
  • 2. What Is Subclassing? Subclassing is a process in which a new class is derived from an old one. It is a distinct concept from (subtype) polymorphism, generalization/specialization and composition. Michal P´se (CTU in Prague) ıˇ Object Programming Lect. 4: Inheritance October 19, 2010 2 / 12
  • 3. Subclassing = Subtyping Subtypes are not required to share any code with their supertypes. Michal P´se (CTU in Prague) ıˇ Object Programming Lect. 4: Inheritance October 19, 2010 3 / 12
  • 4. Subclassing = Subtyping Subtypes are not required to share any code with their supertypes. On the other hand, subtypes are required to stick to the contract of their supertype (the Liskov substition principle). Michal P´se (CTU in Prague) ıˇ Object Programming Lect. 4: Inheritance October 19, 2010 3 / 12
  • 5. Subclassing = Subtyping Subtypes are not required to share any code with their supertypes. On the other hand, subtypes are required to stick to the contract of their supertype (the Liskov substition principle). Subtyping only concerns behavior, subclassing only concerns code. Michal P´se (CTU in Prague) ıˇ Object Programming Lect. 4: Inheritance October 19, 2010 3 / 12
  • 6. The Fallacy of Current Industrial Programming Languages In Java (and many other languages) subclassing implies subtyping, in other words, every subclass has to stick to the contract of its parent class. That severly limits possible code reuse! Michal P´se (CTU in Prague) ıˇ Object Programming Lect. 4: Inheritance October 19, 2010 4 / 12
  • 7. Example void DFS(Node n) { addToStack( n); while ( stackNotEmpty()) { n = removeFromStack(); processNode( n); for ( Node c: n.children()) addToStack( c); } } Michal P´se (CTU in Prague) ıˇ Object Programming Lect. 4: Inheritance October 19, 2010 5 / 12
  • 8. Example Obviously, addToStack void DFS(Node n) { inserts a node at the addToStack( n); beginning of a list and while ( stackNotEmpty()) { removeFromStack removes n = removeFromStack(); a node from the beginning processNode( n); of that list. for ( Node c: n.children()) addToStack( c); } } Michal P´se (CTU in Prague) ıˇ Object Programming Lect. 4: Inheritance October 19, 2010 5 / 12
  • 9. Example Obviously, addToStack void DFS(Node n) { inserts a node at the addToStack( n); beginning of a list and while ( stackNotEmpty()) { removeFromStack removes n = removeFromStack(); a node from the beginning processNode( n); of that list. for ( Node c: n.children()) addToStack( c); Is it correct to override } addToStack to insert a } node at the end of the list? Michal P´se (CTU in Prague) ıˇ Object Programming Lect. 4: Inheritance October 19, 2010 5 / 12
  • 10. Example (II) Not in Java—the new subtype would break the contract of the supertype. Michal P´se (CTU in Prague) ıˇ Object Programming Lect. 4: Inheritance October 19, 2010 6 / 12
  • 11. Example (II) Not in Java—the new subtype would break the contract of the supertype. However, it is perfectly legitimate in languages where subclassing does not imply subtyping—the new class simply isn’t type-compatible with the old one. Michal P´se (CTU in Prague) ıˇ Object Programming Lect. 4: Inheritance October 19, 2010 6 / 12
  • 12. Subclassing = Specialization Subclassing does not imply specialization—subclass does not have to be a specialized version of superclass. Michal P´se (CTU in Prague) ıˇ Object Programming Lect. 4: Inheritance October 19, 2010 7 / 12
  • 13. Subclassing = Specialization Subclassing does not imply specialization—subclass does not have to be a specialized version of superclass. Specialization does not imply subclassing—a specialized version of object does not have to share code with the base case. Michal P´se (CTU in Prague) ıˇ Object Programming Lect. 4: Inheritance October 19, 2010 7 / 12
  • 14. Subclassing = Specialization Subclassing does not imply specialization—subclass does not have to be a specialized version of superclass. Specialization does not imply subclassing—a specialized version of object does not have to share code with the base case. In fact, subtyping and specialization are distinct notions as well. Michal P´se (CTU in Prague) ıˇ Object Programming Lect. 4: Inheritance October 19, 2010 7 / 12
  • 15. Subclassing = Composition Subclassing and composition both facilitate code reuse. Is there anything that can be achieved by subclassing and not achieved by composition or vice versa? Michal P´se (CTU in Prague) ıˇ Object Programming Lect. 4: Inheritance October 19, 2010 8 / 12
  • 16. Poor Man’s Inheritance class Foo { class Qux { void bar() {...} Foo foo = new Foo(); int baz() {...} void bar() { } foo.bar(); } int baz() { return foo.baz(); } } Michal P´se (CTU in Prague) ıˇ Object Programming Lect. 4: Inheritance October 19, 2010 9 / 12
  • 17. Poor Man’s Inheritance class Foo { class Qux { void bar() {...} Foo foo = new Foo(); int baz() {...} void bar() { } foo.bar(); } int baz() { return foo.baz(); } } Emulation of inheritance using composition is far from perfect—method overriding can be emulated only in the simplest cases. Michal P´se (CTU in Prague) ıˇ Object Programming Lect. 4: Inheritance October 19, 2010 9 / 12
  • 18. The Essence of Inheritance So what exactly is inheritance? Michal P´se (CTU in Prague) ıˇ Object Programming Lect. 4: Inheritance October 19, 2010 10 / 12
  • 19. The Essence of Inheritance So what exactly is inheritance? Inheritance is a mechanism facilitating code reuse. Michal P´se (CTU in Prague) ıˇ Object Programming Lect. 4: Inheritance October 19, 2010 10 / 12
  • 20. The Essence of Inheritance So what exactly is inheritance? Inheritance is a mechanism facilitating code reuse. It can be thought about as the C-style include with overriding. Michal P´se (CTU in Prague) ıˇ Object Programming Lect. 4: Inheritance October 19, 2010 10 / 12
  • 21. The Essence of Inheritance So what exactly is inheritance? Inheritance is a mechanism facilitating code reuse. It can be thought about as the C-style include with overriding. It enables reuse even in ways the original code creator never imagined. Michal P´se (CTU in Prague) ıˇ Object Programming Lect. 4: Inheritance October 19, 2010 10 / 12
  • 22. Implementation of Inheritance C++: virtual methods table. Michal P´se (CTU in Prague) ıˇ Object Programming Lect. 4: Inheritance October 19, 2010 11 / 12
  • 23. Implementation of Inheritance C++: virtual methods table. In Smalltalk: method dictionary. Michal P´se (CTU in Prague) ıˇ Object Programming Lect. 4: Inheritance October 19, 2010 11 / 12
  • 24. Implementation of Inheritance C++: virtual methods table. In Smalltalk: method dictionary. In systems with runtime: inline cache. Michal P´se (CTU in Prague) ıˇ Object Programming Lect. 4: Inheritance October 19, 2010 11 / 12
  • 25. See Taivalsaari, A. On the notion of inheritance. ACM Computing Surveys 28, 3 (Sep. 1996), 438–479. http://doi.acm.org/10.1145/243439.243441 Michal P´se (CTU in Prague) ıˇ Object Programming Lect. 4: Inheritance October 19, 2010 12 / 12