[Prev][Next][Index][Thread]
Re: simple method dispatch question
In article <Yd_O5.37450$n9.1230204@news2.rdc1.on.home.com>,
Michael T. Richter <mtr@ottawa.com> wrote:
>"Bruce Hoult" <bruce@hoult.org> wrote in message
>bruce-DCB034.09591111112000@news.nzl.ihugultra.co.nz">news:bruce-DCB034.09591111112000@news.nzl.ihugultra.co.nz...
>>> I was always wondering why I'd want to have an argument to a
>>> function with a specific value instead of a specific type.
>>> Now I see why.
>
>> define method action(obj :: <button>, what == mouseDown)
>> obj.highlight();
>> end;
>
>> define method action(obj == saveButton, what == mouseUp)
>> SaveDocument();
>> end;
>
>> define method action(obj == menuBar, what == mouseDown)
>> DisplayMenu();
>> end;
>
>This looks interesting, but it seems to me to obfuscate semi-trivial (and
>very conventional) conditional logic using the dispatch mechanism. Doesn't
>this tend to make write-only code outside of trivial examples?
The problem with using conditional logic is that it's not easily
extensible, like method dispatch is. To add a new event, you have to
modify the conditional statement, rather than just adding a method.
One of the other posters said that when he said "singleton" he wasn't
talking about the Design Pattern with this name, and he thought it was
unfortunate that Dylan used the same term. But in fact, Dylan's singletons
*are* the Singleton Design Pattern. The difference is that they're built
into the language, so you don't have to define classes to implement
singletons. And the explanation I gave above is the reason why the
Singleton Design Pattern exists.
--
Barry Margolin, barmar@genuity.net
Genuity, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
Follow-Ups:
References: