Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Is this the correct way to think of "base class"?

Reply
Thread Tools

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

 
 
Ravi
Guest
Posts: n/a
 
      09-11-2008
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.
 
Reply With Quote
 
 
 
 
Kai-Uwe Bux
Guest
Posts: n/a
 
      09-11-2008
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
 
Reply With Quote
 
 
 
 
James Kanze
Guest
Posts: n/a
 
      09-12-2008
On Sep 12, 1:54 am, Kai-Uwe Bux <jkherci...@gmx.net> 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
 
Reply With Quote
 
Juha Nieminen
Guest
Posts: n/a
 
      09-12-2008
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.)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
New user - correct way to think and write code Ashley Wharton Ruby 4 02-12-2008 07:35 AM
Need help: Is Quick-Union-Find the right solution to this problem (Now I don't think so and I think that topological sorting should be the way to go...?) ? aredo3604gif@yahoo.com C Programming 1 04-13-2005 12:48 AM
Need help: Is Quick-Union-Find the right solution to this problem (Now I don't think so and I think that topological sorting should be the way to go...?) ? aredo3604gif@yahoo.com C Programming 0 04-12-2005 05:06 PM
Think your Wireless Network is Secure? Think Again. Careers Computer Security 7 01-31-2004 07:04 AM
Think Off Brand Inks Are Just as Good in your Inkjet Printer - Think Again! John Horner Digital Photography 5 11-09-2003 09:38 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57