Re: Inheritance

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Yes I think you are right, it is a bad design. I have changed the design now
so that,
class a:public CObject
class b:public CObject
class c: public b
a = League
b = Session
c = Division
I had this all screwed up because I was trying to have multi arrays of
different classes. Now I have separated League from Session, derived Division
from Session and will save Division in a CTypedPtrArray.
I have not gotten around to it yet because I am redoing alot of my
application because of some posts that I have read about a proper design. I
think that the way that I am going to use the previous classes and the way
that I am going to save them will work. If you see something that does not
look right please let me know.
Thanks!
--
Just Al


"Joseph M. Newcomer" wrote:

Only if the pilot is rated for aerobatics...

(Couldn't resist...)

Yes, that's another case. It gets trickier, and inheritance breaks down after a while.

class WheeledVehicle {
public:
int wheels;
};

class Unicycle : public WheeledVehicle
public:
Unicycle() : wheels(1) { }
};

class WingedVehicle {
public:
int wings;
int engines;
};

class biplane: public WheeledVehicle, WingedVehicle {
public:
biplane () : wings(4), wheels(3)
};

class monoplane : public WheeledVehicle, WingedVehicle {
public:
monoplane() : wings(2) {}
};

class glider : public monoplane {
public:
glider () : engines(0), wheels(2) {}
};

class Bomber : public monoplane {
int BombLoad;
};

class PoweredPlane {
public
int engines;
typedef { Piston, Jet } EngineType;
EngineType type;
};

class PropPlane {
public:
int bladesperprop;
};

class Jet : public PoweredPlane {
public:
Jet() : type(Jet);
};

class B52 : public monoplane, bomber, Jet {
public:
B52() : engines(8), wheels(8), BombLoad(CLASSIFIED_VALUE) {}
};

class C130 : public monoplane, Jet, PropPlane {
public:
C130: engines(4), wheels(8), bladesperprop(4) {}
}

Given this hierarchy, I can probably come up with actual planes that don't fit it. And on
the whole, you can't do it without multiple inheritance. What about a jet-propelled race
car, or even a jet-propelled bicycle? What about model airplanes powered by rubber bands?
We used to go through exercises like this back when we were designing inheritance
languages, and it became a weekly exercise to describe vehicles. For example, how do you
describe an airplane with skis or pontoons instead of wheels? Oh, forgot about that. So
a new hierarchy comes around. What about bulldozers or tanks with treads instead of
wheels? A halftrack? A snowmobile? This was in the days before the Internet and Google,
and we would spend hours in the library looking for photos of odd vehicles that our
current hierarchy couldn't describe, and try to work out a new hierarchy that could
describe all vehicles (hot air balloons, dirigibles, hang gliders, kites, roller skates,
skateboards,helicopters, autogyros, ...wow! It's been thirty years, and what I remember
was that we couldn't get a decent solution. The really bad thing was that we couldn't
somehow attach attributes, but our whole hierarchy would disintegrate. The folks in AI
developed entirely different mechanisms for describing objects, that were
non-hierarchical.

So hierachical systems will give superficially simple solutions to trivial problems, but
they dont' give solutions to all representations.

Note that I stopped at weeks in my description, because months get trickier, and what's a
year? 365, 366, or 365.25?

Key here is that anything in class A should only reference classes that are not related,
or its superclasses, but not its subclasses. Once you start building circular
dependencies, life gets fairly miserable. And you can't do anything that requires that
the superclass have instances of the subclass, although it could have pointers to a
subclass, but at this point you're into really weird, and probably very bad, design.
joe

On Wed, 28 Mar 2007 09:44:07 -0700, Al <Al@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:

Would the post before this one with airplane as a class inverted also?
Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm

.



Relevant Pages

  • Re: Inheritance
    ... CString GetTeammascot(); ... int FindTeam; // Get the index for a particular team given their team name by looping through list ... class glider: public monoplane { ... Given this hierarchy, I can probably come up with actual planes that don't fit it. ...
    (microsoft.public.vc.mfc)
  • Re: Inheritance
    ... int wheels; ... class Unicycle: public WheeledVehicle ... class glider: public monoplane { ... Given this hierarchy, I can probably come up with actual planes that don't fit it. ...
    (microsoft.public.vc.mfc)
  • RE: Database deign problem
    ... Typically, if I want to design a hierarchy that has more than 2 levels, I ... OBJECT_ID int auto ... PARENT_OBJECT_ID int ...
    (microsoft.public.sqlserver.datawarehouse)
  • Re: ID and Creationism
    ... that type of nested hierarchy can be a parsimonious ... > So, Zach, if we humans are more than capable of making nested ... That is the hallmark of design. ... We can infer from Common Descent that the centaur ...
    (talk.origins)
  • Re: The universe looks designed to me
    ... >hierarchies and what kind of evidence they really are. ... >aircraft could be categorized as such - beginning with the first flight ... >Is this nested hierarchy evidence for evolution among aircraft? ... So this nested hierarchy is evidence of an evolution of *design*. ...
    (talk.origins)