On 11 September 2012 14:35, Stéphane Ducasse <[email protected]> wrote:
> Hi igor
>
> I started to reread again the code of EventModel that we started and I browse
> the rest of the system….
> gloops…
>
> DropEvent>>sentTo: anObject
> "Dispatch the receiver into anObject"
> self type == #dropEvent ifTrue:[^anObject handleDropMorph: self].
>
> DropFilesEvent>>sentTo: anObject
> "Dispatch the receiver into anObject"
> self type == #dropFilesEvent ifTrue:[^anObject handleDropFiles: self].
>
> it seems to me that sentTo: is a kind of double dispatch but not yet there.
> I do not see here the added value of the check except if this is to cancel
> event.
>
rofl.. you managed to force me to say "wtf" loudly, just after i seen
these two methods. Congratulations! :)
And after looking at those classes, i found that those checks is
completely useless because they are always yielding true:
DropEvent>>type
^#dropEvent
DropFilesEvent>>type
^#dropFilesEvent
and dispatch is always performed. And i don't see why would anyone
want to cancel event in such fashion, because if you don't wanna
handle it, then just don't send #sentTo: or make sure that end
receiver of double-dispatch just ignores such kind of events.
I must admit, that a double-dispatch is one of my favorite hammers i
use , because i think it one of the best ways for dealing with
polymorphism.
But before i started using smalltalk i almost never used
double-dispatch in my code, and in other places where i found it , was
confusing me a lot..
This is because in other languages you tend to use case statements
instead, because the amount of coding to implement double-dispatch is
too verbose comparing
to little case-statement .. this is of course says a lot about
expressive power of smalltalk.. and of course, it would be much more
difficult to determine if given piece of code actually a
double-dispatch or not, unless you can see all implementors & senders
using browser, but instead will have to go through multiple files to
determine that (because again, most so-called OO languages best
practices saying that you should use one file per class).
--
Best regards,
Igor Stasenko.