Topic: mating dogs and cats (run-time type checking)


Author: tmb@arolla.idiap.ch (Thomas M. Breuel)
Date: 28 Jul 92 16:19:57 GMT
Raw View
In article <1992Jul23.154254.5306@ucc.su.OZ.AU> maxtal@extro.ucc.su.OZ.AU (John MAX Skaller) writes:

   The problem is why you proposed 'thisclass' and is a real problem.
   It is a problem for which RTTI is the wrong solution,
   but never-the-less is the best we will get for a while.
   We really need multiple dispatch.

   class Animal {
    int mate(Animal&);
   };
   class Dog : Animal {
    int mate (Animal&);
   };

   We REALLY want Dog::mate(Dog&), but we cant have it.

I don't see the problem.

class Animal {
 virtual int mate(Animal &) = 0;
 virtual int mate_dog(Animal &other) {error("not a dog");}
 virtual int mate_cat(Animal &other) {error("not a cat");}
};

class Dog {
 int mate(Animal &other) {return mate_dog(other);}
 int mate_dog(Animal &other) { ... do it the way dogs do it ... }
};

   This is a flaw in Object Oriented Programming IMHO.
   The solution requires multimethods which are inherently
   functional.

I don't see that this particular thing is a flaw with Object Oriented
programming. Nor do you need RTTI to solve this problem.

I assume that by "functional" you mean "CLOS-style methods". I agree
that they are more convenient and easier to maintain, but at least in
this respect, they don't give you more functionality.

     Thomas.