[Prev][Next][Index][Thread]
Re: Dynamic inheritance
dauclair@hotmail.com writes:
> So, I need to dispatch on the suit as well as on the face (as well as
> on some special faces).
Can you make suit and face slots of <card> and have your dispatching
method on <card> call another method that dispatches on the slots?
Something like:
define class <card> (<object>)
virtual constant slot card-value;
slot card-face;
slot card-suit;
end;
define generic do-card-value( face, suit );
define method card-value( card :: <card> )
do-card-value( card.card-face, card.card-slot );
end;
define method do-card-value ( face == #"jack", suit == #"hearts" )
// return value here
end;
define method do-card-value ( face == #"jack", suit == #"spades" )
// return value here
end;
// etc.
> 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?
Just the above, which is pretty much your suggestion, just that the
user doesn't explicitly call the function with the slots as the
parameter.
Chris.
--
http://www.double.co.nz/dylan
References: