



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




Introduction
implemented?
Inheritance
support for specifying general concepts (through class mechanism) as well support for specializing concepts. Various terms used for inheritance: concatenation , sub-classing , derivation , and prefixing.
Additional methods (iii) Redefinition of methods and states (iv) Deletion of methods and states.
immediate descendant
superclass and subclass an inheritance graph; Nodes of graph: Class, Edges: class-subclass relationship.
one class.
X R
class will be when
Inheritance
Subtype principle : An object of a subtype may be used anywhere its super-type can be used.
of inheritance for implementation accidental.
separate inheritance from sub-typing. In languages such as C++, it occurs within a single framework.
How does the inherited interface look like?
Draw, Initialize, Offset, SetWidth
additional methods.
How does implementation inheritance look?
Why inheritance?
s.c cc s.o
procedure draw(Diagram d) begin for each Shape s in d do begin case s of BOX: draw_box(); ELLIPSE: draw_ellipse(); LINE: draw_line(); TEXT: draw_text(); ... end
statement at different places. User is managing various types through constant definitions and case statements.
How can inheritance help?
Support for interface inheritance in Java
Support for inheritance in C++
implementation of methods. It can override the implementation of methods by re-implementing them.
Support for inheritance in Java
class Shape { ... public: virtual void Draw(Shape *) { .. } } class Ellipse: public Shape { public: virtual void Draw(Shape *); }
according to the type of object. (All subclasses don’t have to re-implement them).
Dynamic Binding
Abstract Classes
Method invocations of subclasses
Why not? Because they do not have corresponding definitions for subclasses.
destructor on corresponding objects should be called. A rule of thumb: declare a virtual destructor for every base class that has a virtual function.
int a; int b; int c;
Most languages (including C++) do not guarantee the order in which storage is allocated for derived classes.
int a; int b; int c; vptr
vtbl: &A::f
&C::h
&B::g