Re: Double Dispatch Problem: Mobile Creatures and Projectiles in a Game World
- From: Ed Kirwan <iamfractal@xxxxxxxxxxx>
- Date: Fri, 30 Mar 2007 12:55:27 +0200
Aaron J. M. wrote:
But how would a Collision check whether the colliding Mobiles are one
of each
without downcasting, double dispatch, or the Visitor pattern?
I might end up doing the Visitor pattern, but I want to put it off for
now to
see if I can find an easier solution.
It appears OO has a problems when comparing classes, 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):
Thing extends Visitor {
void execute(Thing thing) {
thing.visit(this);
void accept(Liquid liquid) {
System.out.println("The " + liquid + " seeps through your fingers.");
}
void accept(Solid solid) {
System.out.println("You take the " + solid);
}
}
class Solid extends Thing {
void visit(Verb verb) {
verb.accept(this);
}
}
etc.
I'm trying to get my head around the good Mister Lahman's suggestion from your link that, "If some types of active
tokens are limited in what they can do with some types of inanimate
objects, that has to be expressed in the relationships properly. "
I'd love if that line held the answer for me ...
(OT: I can never remember which takes the accept() and which takes the visit(); must dust off GOF again.)
..ed
--
www.EdmundKirwan.com - Home of The Fractal Class Composition.
Download Fractality, free Java code analyzer:
www.EdmundKirwan.com/servlet/fractal/frac-page130.html
.
- Follow-Ups:
- 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
- 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.
- Double Dispatch Problem: Mobile Creatures and Projectiles in a Game World
- Prev by Date: Re: Long Life Objects
- Next by Date: Re: Double Dispatch Problem: Mobile Creatures and Projectiles in a Game World
- 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
|