Is this the correct way to think of "base class"?

Discussion in 'C++' started by Ravi, Sep 12, 2008.

  1. Ravi

    Ravi Guest

    Is this the correct way to think of "base class"?

    The "base class" is a class from which other classes are derived.

    The "base class" will never be derived from another class.
     
    Ravi, Sep 12, 2008
    #1
    1. Advertising

  2. Ravi

    Kai-Uwe Bux Guest

    Ravi wrote:

    > Is this the correct way to think of "base class"?


    No.

    > The "base class" is a class from which other classes are derived.


    Yes. More carefully, one would say that a base class is designed to be
    derived from in some form typical for bases (e.g., with a virtual
    destructor). This is to distinguish base classes from other classes that
    also work through derivation like policies or convenience classes such as
    std::unary_function. Whether one wants to make such a distinction, is a
    matter of taste and context.

    In the end "base class" is a term that makes sense in the context of a
    particular design.


    > The "base class" will never be derived from another class.


    No, at least, I would not see a reason for that.



    In general: __ is derived from __ is a binary predicate. It is not true that
    every class occurs in at most one spot of that relation. It is also not
    true that the mechanism of derivation only plays a role in object oriented
    design. In C++, derivation is a pretty liberal concept.


    Best

    Kai-Uwe Bux
     
    Kai-Uwe Bux, Sep 12, 2008
    #2
    1. Advertising

  3. Ravi

    James Kanze Guest

    On Sep 12, 1:54 am, Kai-Uwe Bux <> wrote:
    > Ravi wrote:


    [...]
    > In general: __ is derived from __ is a binary predicate. It is
    > not true that every class occurs in at most one spot of that
    > relation. It is also not true that the mechanism of derivation
    > only plays a role in object oriented design. In C++,
    > derivation is a pretty liberal concept.


    Along those lines, I like to distinguish between derivation and
    inheritance, using the word "derivation" for an implementation
    technique in the C++ language, and "inheritance" for an OO
    design concept. Not all instances of derivation are
    inheritance, and it's possible to implement inheritance without
    using derivation (since you can use inheritance in C).

    --
    James Kanze (GABI Software) email:
    Conseils en informatique orientée objet/
    Beratung in objektorientierter Datenverarbeitung
    9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
     
    James Kanze, Sep 12, 2008
    #3
  4. James Kanze wrote:
    > Along those lines, I like to distinguish between derivation and
    > inheritance, using the word "derivation" for an implementation
    > technique in the C++ language, and "inheritance" for an OO
    > design concept. Not all instances of derivation are
    > inheritance, and it's possible to implement inheritance without
    > using derivation (since you can use inheritance in C).


    Some people also make the distinction between specializing, extending
    and implementing a base class.

    - Specialization: The purest OO concept of inheritance: The derived
    class is a more concrete concept than the base class, which is a more
    abstract, generic concept. The classical "Animal -> Dog" inheritance is
    an example of specialization: "Animal" is a more generic, more abstract
    concept, while "Dog" is a more concrete, more specialized concept. This
    follows the classical "is-a" relationship ("a Dog is an Animal").

    - Extension: The purpose of the inheritance is to have a class with the
    same features as another class, but with additional features added. The
    derived class supports everything that the base class supports, plus
    more. This design principle is sometimes used to avoid code repetition:
    If more than one class should have the exact same common
    functionalities, those common functionalities are put into a common base
    class and the actual classes derived from this. Whether this is a simple
    case of code reuse or more of an "is-a" relationship depends on the
    situation.

    - Implementation: Mostly relevant with interfaces and abstract classes,
    ie. classes which contain pure virtual functions which must be
    implemented in a derived class. Especially the so-called interfaces
    might contain nothing else than pure virtual functions, and their sole
    purpose is to function as callback objects or similar. (Some might argue
    that this is just a form of specialization. However, it does have its
    own separate uses and idioms, eg. the already mentioned callback mechanism.)
     
    Juha Nieminen, Sep 12, 2008
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    647
  2. Replies:
    1
    Views:
    913
    Jack Klein
    Apr 13, 2005
  3. Alf P. Steinbach
    Replies:
    6
    Views:
    573
    John Carson
    Sep 3, 2005
  4. Ashley Wharton
    Replies:
    4
    Views:
    117
    Robert Klemme
    Feb 12, 2008
  5. David Mark
    Replies:
    17
    Views:
    268
    David Mark
    Mar 23, 2010
Loading...

Share This Page