Why ABC's make bad Interfaces

From: christopher diggins (cdiggins_at_videotron.ca)
Date: 04/08/04


Date: Thu, 8 Apr 2004 15:05:26 -0400

The following is from an article I placed on the HeronFront web site (
http://www.heron-language.com/heronfront.html ) which attempts to explain
the differences between Abstract Base Classes (ABC) and Interfaces :

--
Many programmer's make the mistake of assuming that an interface is
equivalent to an Abstract Base Class (ABC). This is an easy mistake to make
because it is common practice to implement an interface using ABC's.
An ABC provides virtual functions that are overridden in the inheriting
class, which in many object oriented programing language (OOPL)
implementations means that each instance of the implementing (inheriting)
class requires a new vtable for each inherited ABC.
The problem with the ABC approach is that we have code bloat within objects
because of each vtable. Our objects can rapidly become too big and slow due
to all of the neccessary vtables and lookups.
In contrast with ABC's, when we talk of a class implementing an interface,
we know that there will only ever be one implementation function for each
method so there is no reason for a vtable. In order to refer to an object by
its interface without knowing its type we can do this with "fat" pointer
made up of two pointers, one to the object instance and another to a static
interface function lookup table.
-- 
I am interested in hearing any comments on this post, in order to make it as
accurate and non-language biased as possible. TIA.
Christopher Diggins
http://www.cdiggins.com
http://www.heron-language.com


Relevant Pages

  • Re: Why ABCs make bad Interfaces
    ... > equivalent to an Abstract Base Class (ABC). ... > because it is common practice to implement an interface using ABC's. ... To convert an object to its interface, you return a fat pointer ... The NaiveInt constructor has to set up the vtables, ...
    (comp.object)
  • Re: Why ABCs make bad Interfaces
    ... >equivalent to an Abstract Base Class. ... >because it is common practice to implement an interface using ABC's. ... >class requires a new vtable for each inherited ABC. ... >to all of the neccessary vtables and lookups. ...
    (comp.object)
  • Re: Why ABCs make bad Interfaces
    ... > memory used by the vtables becomes an issue? ... >> mistakenly specifying the interface functions as being virtual, ... This is why an ABC is not an Interfaces. ... Christopher Diggins ...
    (comp.object)
  • Re: Why ABCs make bad Interfaces
    ... >equivalent to an Abstract Base Class (ABC). ... >because it is common practice to implement an interface using ABC's. ... and each vtable is a union of all its base class vtables. ... pointer per fat pointer instead of one vtable pointer per object. ...
    (comp.object)
  • Re: Declaring a Constructor in an Interface?
    ... ABC: ... Interface: ... >> static void SpeedTestInterface ... > implementing IFoo. ...
    (microsoft.public.dotnet.languages.csharp)