[Prev][Next][Index][Thread]
Re: simple method dispatch question
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?
By the same argument you could replace polymorphism with conditional
logic. -- I'm not sure whether I mean this as a reductio ad absurdum or
as a serious consideration.
What makes dispatch on singleton arguments attractive, in my view, is
that extensions are unlikely to affect existing logic.
Michael
--
Michael Schuerig
mailto:schuerig@acm.org
http://www.schuerig.de/michael/
Follow-Ups:
References: