Re: Abstract Data Types - Separating Interface from Implementation

From: Jeffrey Schwab (jeffplus_at_comcast.net)
Date: 12/24/03

  • Next message: Nicholas Hounsome: "Re: files,overload"
    Date: Wed, 24 Dec 2003 09:13:40 -0500
    
    

    Correction:

    >> 4) Are abstract data types "abstract" because they are specified
    >> separate to implementation?

    I see now that you were asking about abstract data types, not abstract
    classes. Abstract, in the sense you used it, means only that the
    implementation is hidden from the user. This usually means an extra
    level of redirection is needed, and the redirection is usually through a
    pointer. One popular approach is to have a *factory* or static method
    return a pointer to a class implementing the interface, and another is
    the "pimpl" method John Carson already mentioned.

    > No. An abstract class is special, in that it does not have definitions
    > for all of its methods. Such an undefined method is called "pure
    > virtual." Since the class is not completely defined, it can never be
    > instantiated; that's what makes it "abstract." Such a class is useful
    > because each class "derived" from it can provide a different
    > implementation of each virtual function. This feature supports a design
    > style called "polymorphism." To understand polymorphism, you first need
    > to have a basic understanding of a technique called "inheritance." See
    > chapter 12 of TC++PL.


  • Next message: Nicholas Hounsome: "Re: files,overload"

    Relevant Pages

    • sizeof(object) is different in ANSI and Unicode
      ... A class having no member variables and only a method sizeof ... I have the answer for this of how in works in ANSI. ... form a pointer to an empty object that is distinct from a pointer to ... For a class with virtual function, size of a virtual function is a ...
      (comp.lang.cpp)
    • Re: Why sizeof(struct) is different in C and C++ ?
      ... >> My conceptual view is a stack of base classes, ... For "ordinary" inheritance where each class inherits from exactly one immediate ... for just a single virtual function table pointer. ...
      (comp.lang.cpp)
    • Re: is it good, is it bad or plain eeevil ?
      ... > This is a virtual function call regardless of how call_vfun was called ... If sword is 'given' to player (that is pointer is passed), ... virtual method. ...
      (comp.lang.cpp)
    • Re: Would a static_cast be better style here?
      ... >> And of course to convert from a derived pointer type to a base pointer ... > pointer, then you are correct, there is no need to cast. ... For a virtual function the scope resolution operator is the only way. ...
      (comp.lang.cpp)
    • Re: memory usage of Virtual function poiters
      ... > That won't compile either. ... I forgot the cast. ... >> percolate through the virtual function table. ... behavior of casting a pointer to a pointer of sibling class. ...
      (alt.comp.lang.learn.c-cpp)