[Prev][Next][Index][Thread]
Dynamic inheritance
-
To: info-dylan@ai.mit.edu
-
Subject: Dynamic inheritance
-
From: dauclair@hotmail.com
-
Date: Mon, 27 Mar 2000 21:45:02 -0500 (EST)
-
Organization: Deja.com - Before you buy.
-
Xref: traf.lcs.mit.edu comp.lang.dylan:11750
I'm implementing a card game called set-back (my Nana's favorite game,
if you must know):
// ---- code ----
define class <suit> (<object>) end;
define class <hearts> (<suite>) end;
// ...
define class <face> (<object>) end;
define class <jack> (<face>) end;
// ...
// define class <card> (<suit>, <face>) end; // ???
// the above definition legal, but I want _A_ card to
// be a subclass of a _specific_ suit and a _specific_
// face.
// -- end-code --
The question is: how do I create a local <card> variable that is an
object of an unknown <face> and unknown <suit>, specifically so that
the dispatch mechanism resolves the cards properly.
<rules-detour>
(e.g. *trumps* may be set to <clubs>, and a trump card beats all other
(non-trump) cards.) Jacks and 10s have special (scoring) properties,
as well as the high (usually the ace) and low card (usually the deuce)
of the trump.
</rules-detour>
So, I need to dispatch on the suit as well as on the face (as well as
on some special faces).
Does Dylan have a dynamic inheritance mechanism? If not, what are some
common ways to handle this problem? I've thought of having state slots
on <card> and dispatching on them by calling a fn with the slots as
parameters (State(305) indirection), but that's a bit more work than
DI. Any other suggestions?
Sincerely,
Doug Auclair
Sent via Deja.com http://www.deja.com/
Before you buy.
Follow-Ups: