Sunday, June 24, 2007

differnentiate between inheritance of interface and inheritance of implementation


the difference between these two is same as the difference between function declaration and function definition.

member function interfaces are always inherited.public inheritance means that trivially
the purpose of declaring a pure virtual function is to havea a dervied class inherit a function interface only.

you can provide a definition for a pure function also, but not a ver useful thing in general.

the purpose of declaring  simple virtual functions is to have derived classes inherit a function interface as well as a default implementation.

to avoid the chance of forgetting to define a proper version when a new class comes in, then you can define a function in the interface that is pure virtual and have it call a portected virtual function to do the actual thing.

that way every new class has to define the virtual function and it gets you
a non virtual member function specifies and invariant over specialization

pure virtual - interface only
simple virtual --interface and  default implementation
non virtual -- interface and a mandatory implementation

things to remember:
inheritance of interface is different from inheritance of implementation. under public inheritance derived calsses always inherit base class interfaces.
pure virtual functions specift inheritance of interface only
simple virtual functions specify inheritance of interface plus inheritance of a default implementation.
non virtual functions specift inheritance of interface plus inheritance of a mandatory implementation



No comments: