[Prev][Next][Index][Thread]

Re: simple method dispatch question



On Fri, 10 Nov 2000 11:15:01 -0500 (EST), johncwhi@my-deja.com wrote:

> Is it possible to force calling a particular instance of a generic
> function-- a super class' instance--when you have an object which
> inherits from two different super classes?   

Basically no. You have to do through an explicit protocol:

define class <test> ( <object> )
end class <test>;


define class <test1> (<object> )
end class <test1>;



define class <mixed-test> ( <test>, <test1> )
end class <mixed-test>;



define method print-as-test ( x :: <test> )
   // do stuff
end method print;

define method print ( x :: <test> )
   print-as-test( x );
end method print;


define method print-as-test1 ( x :: <test1> )
   // do more printing stuff
end method print;

define method print ( x :: <test1> )
   print-as-test1( x );
end method print;


define method print ( x :: <mixed-test> )
   print-as-test( x );
end method print;

There may be a way of introspecting through methods and calling what seems to
be the right one, but I wouldn't recommend it.

__Jason


Follow-Ups: References: