Mail Archives: djgpp/1996/10/11/13:56:24
A.Appleyard wrote:
> If you define these codes:-
> enum{_unknown=0, _spaceship=1, _star=2, _missile=3; .....};
> and if you make sure that spaceship.sort==1, star.sort==2, etc, always,
> then (I think) you can convert back:-
>
> switch(X.sort) {
> case _spaceship: S=(spaceship*) X; .... handle a spaceship ....; break;
> case _star: C=(star*) X; .... handle a star ....; break;
> etc etc;};
If you're doing this, then you're not taking advantage of object-oriented
programming correctly.
Consider; Under what cases would you need to do this case-by-case
breakdown of the behavior of specific (i.e., derived) objects? What you
should be doing is wrapping _those_ actions in a virtual member function
which is overridden in subsequently derived classes.
So in the case of the example you give, you'd have an Object::Handle member
function, which would be overridden by each of the derived classes. In
_these_ is where object-specific code would occur, not in some global
function which breaks down the individual objects case by case.
Generally if you find yourself in a situation where you think you have to
do this kind of thing to get around a problem, it means you're not using
object-oriented design properly -- you should rethink your class hierarchy
and how the different classes interact with one another.
> What's a signature? What variant of C does it occur in?
Signatures are a gcc-specific C++ extension. Come to think of it, it may
be in one of the newer draft standards (I know there have been papers on
it), but I don't know how well the idea is accepted in the C++ community
offhand.
--
Erik Max Francis | max AT alcyone DOT com
Alcyone Systems | http://www.alcyone.com/max/
San Jose, California | 37 20 07 N 121 53 38 W
&tSftDotIotE | R^4: the 4th R is respect
- Raw text -