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

Re: simple method dispatch question



"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?





Follow-Ups: References: