Re: Double Dispatch Problem: Mobile Creatures and Projectiles in a Game World
- From: "Dmitry A. Kazakov" <mailbox@xxxxxxxxxxxxxxxxx>
- Date: Fri, 30 Mar 2007 15:25:38 +0200
On Fri, 30 Mar 2007 12:55:27 +0200, Ed Kirwan wrote:
It appears OO has a problems when comparing classes,
Umm, why? Classes are ordered by the <: relation. So you can compare them.
It is not OO problem.
and RTTI in
general. I know of no good solution to your problem, just the visitor;
indeed I experienced it myself when I wrote some interactive fiction.
I had a Verb class and a Thing class. Liquid and Solid were subclasses
of Thing; Take was a subclass of Verb.
When someone took something, I needed the visitor pattern to see what to
do. I don't know how else to do it (without instanceof and other such
unpronouncibles):
That's because in general case multiple dispatch cannot be reduced to
single dispatch. In some specific cases you can simulate it with single
dispatch and re-dispatch, but not always.
In your example it is simple, as you have only Take in the hierarchy of
verbs. Add Drill and it will become impossible.
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
.
- References:
- Double Dispatch Problem: Mobile Creatures and Projectiles in a Game World
- From: Aaron J. M.
- Re: Double Dispatch Problem: Mobile Creatures and Projectiles in a Game World
- From: Dmitry A. Kazakov
- Re: Double Dispatch Problem: Mobile Creatures and Projectiles in a Game World
- From: Aaron J. M.
- Re: Double Dispatch Problem: Mobile Creatures and Projectiles in a Game World
- From: Ed Kirwan
- Double Dispatch Problem: Mobile Creatures and Projectiles in a Game World
- Prev by Date: Re: Is Procedural Paradigm a basis of OO Paradigm?
- Next by Date: Is OOP harder to get right? (Was: Is Procedural Paradigm a basis of OO Paradigm?)
- Previous by thread: Re: Double Dispatch Problem: Mobile Creatures and Projectiles in a Game World
- Next by thread: Re: Double Dispatch Problem: Mobile Creatures and Projectiles in a Game World
- Index(es):
Relevant Pages
|