Re: Why ABC's make bad Interfaces

From: Universe (universe_at_covad.net)
Date: 04/10/04


Date: Fri, 9 Apr 2004 21:17:05 -0400


"christopher diggins" <cdiggins@videotron.ca> wrote in message news:gzAdc.89950

> When I write a class that implements an interface it should not be an
> implicit agreement to make those functions virtual. This conflicts with my
> intentions most of the time.

Best idiomatic pratice with a C++ base class that is meant to serve as the
API for a hierarchy is to declare all methods as 'virtual', without data
members.
Each derived class should declare the data members it requires. If there is
a need for the base class to have a data member it should accessed
via a protected base class member function.

> The
> fact that those functions become virtual is something that is wrongheadly
> imposed by many language implementations.

Either a C++ base class method IS or IS NOT declared 'virtual'. There's no
ambiguity.

> This is why an ABC is not an Interfaces.

Many C++ coders are happily using ABC's as type class hierarchy interfaces.

> At the risk of repeating myself, you can have interfaces at a fraction of
> the speed and size overhead of ABC's.

What's so large and slow about vtbls as employed with C++ class type
hierarchies?

Further one is not limited to inheritance with C++. One may also
use super speedy generics that allow for polymorphic behavior given
the same API.

Elliott

--
http://www.univercenet.net
It has heavily contributed to my subsequent
opinion that creating confidence in the correctness
of his design was the most important but hardest
aspect of the programmer's task. In a world
*obsessed with speed* ["Craftite" just do
it -Ell], this was not a universally popular
notion."  ~EW Dijkstra


Relevant Pages

  • Re: Fans of Template Method with protected variable?
    ... >>I've recently started using protected variables in the super class instead. ... >>ask when you guys implement this pattern do you do it with private variables ... advocates not having base class data members. ...
    (comp.object)
  • Re: Heap corruption in derived class constructor
    ... I have a base class defined with several data members, ... sizeof (BaseRequest) is 56 bytes. ... is a compiled DLL linking to a static library which contains the ...
    (microsoft.public.vc.language)
  • Re: Binary serialization
    ... result is to store its DATA MEMBERS ONLY! ... significantly faster than the binary formatter, ... through some base class/subclass construction: ... array which is then written to the stream by the base class. ...
    (microsoft.public.dotnet.general)
  • Re: Heap corruption in derived class constructor
    ... I have a base class defined with several data members, ... sizeof (BaseRequest) is 56 bytes. ... is a compiled DLL linking to a static library which contains the ...
    (microsoft.public.vc.language)
  • Re: the virtual keyword
    ... > you could not declare a body for it in the class it was declared virtual, ... This class can only be used as a base class, ... would result in a compiler error. ... function pointer that is added to the actual class. ...
    (comp.lang.cpp)