Jun. 15th, 2009
a couple of short notes
Jun. 15th, 2009 11:17 pm1. This Saturday, reading Abadi and Cardelli's "A Theory of Objects", figured out that the idea of ad-hoc polymorphism that is probably the basis of OOP, is just due to the fact that the functor -> is contravariant. So that we can apply a (nominally) superclass method to an instance of subclass.
2. All those events and listeners in Java - how come nobody uses double dispatch there?! People write long sequences of switch cases; what are these switch cases if not a manual dispatch? Do it using the language: have a bunch of specific event subclasses and, in listener's
2. All those events and listeners in Java - how come nobody uses double dispatch there?! People write long sequences of switch cases; what are these switch cases if not a manual dispatch? Do it using the language: have a bunch of specific event subclasses and, in listener's
eventHappened()
call an event methods, something like event.hello(this);
, and different kind of events will call the listener's process()
with the right event type; actually, there's not even a need for having a separate eventHappened()
and process()
; the ubiquitous "event dispatcher" can just call event's hello()
passing the listener. That would be it, no? Am I wrong? Is not it how Erlang does it?