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

Re: methods on make



On Wed, May 9, 2001, Chris Double <chris@double.co.nz> wrote:

>Another example is the make(...) implementation asks another generic
>function passing various initialization parameters which can be
>dispatched on to get the correct class type:
>
>define method class-for-make-widget(class, somearg1 :: <x>)
>  <foo-widget>
>end;
>
>define method class-for-make-widget(class, somearg1 :: <y>)
>  <bar-widget>
>end;
>
>define method make(class == <widget>, #key #rest initargs)
>  apply(make, class-for-make-widget(class, somearg1, somearg2), initargs);
>end method make;

Ah, the Dylan-style solution to the rest of the problem that I was trying
to use as an example. Thanks. 

I guess then this would be a reasonabe guideline for those like me coming
from C++ or Java--any time you need to build some mechanism for dynamic
dispatch (think for example of the way PowerPlant requires registration
of GUI widgets), you should remember to just use the built-in facility of
generic functions with multiple and singleton dispatch.


Scott Ribe
scott_ribe@killerbytes.com
http://www.killerbytes.com/
(303) 665-7007 voice



References: