A forum for questions and answers about network programming on Linux and all other Unix-like systems

You are not logged in.

#1 2006-03-30 03:21 PM

Registered: 2006-02-13
Posts: 53

Re: Association in C++


#2 2006-03-30 04:01 PM

From: Sol 3
Registered: 2002-06-12
Posts: 911

Re: Association in C++

No... I personally don't think there is anything wrong with doing what you described...

As an example why, lets consider a "contrived" example where there is a function "stats" in a class called I dunno... "Tire"... tha represents a perfect wheel for a vehicle... it prints out information about the "perfect" wheel such as tire pressure, how long it will last, and so forth...

Now we extend on tire... we have well... the "ExtendedTire" class... it STILL needs a "stats" function since it has all the attributes of a "Tire" but ALSO might say specify the condition that it lasts 200% of the time of a regular Tire...

So, if ExtendedTire is inheriting from Tire we could re-write all of the Tire "stats" function... but heck... why repeat code, the memory overhead and everything else... After all, the Tire class already provides a lot of the information... so instead, the ExtendedTire would provide ( output or otherwise ) it's extra information... then call it's parent "stats" to retrieve / printout / whatever all the basic info shared by ALL objects that are Tires... possibly modifying it before output or return to the user ( that is, normal tire lasts N time and ExtendedTire lasts 2 * N time )...

Again this is just an example... but because of the example and a lot of similar real life programming situations, my personal feeling is that there is NOTHING with 'chaining' functions from child to parent to pick up additional information etc. ... if the desired functionality is already provided by the parent...

Of course it is possible to do completely absurd things by mis-namining and chaining... but the question doesn't seem to be about purposely trying to break things ;-)


"The only difference between me and a madman is that I'm not mad."

Salvador Dali (1904-1989)


Board footer

Powered by FluxBB