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

R

Ravi

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.
 
K

Kai-Uwe Bux

Ravi said:
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
 
J

James Kanze

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).
 
J

Juha Nieminen

James said:
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.)
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top