The most traditional form of event-driven programming is input-output.
It used to be the case that the program drives the user “please input your value now”. Nowadays the user is in charge “when a user presses a button, execute that action” A typical pattern is observing a value, between a subject and observer of publisher and subscriber.
Some events are characterized just by the fact of their occurrence. Others (like a mouse click at position x,y) have arguments. A traditional architecture solution is obviously the Observer Pattern. Bertrand remarks that Martin Odersky has written a paper explaining why this pattern should be depricated. Martin summarizes this paper by saying that higher level dataflow is better.
Bertrand argues that another disadvantage of the observer pattern is that it is impossible to generalize it and this makes reuse hard. To do so we need the power to abstract. To be practical, we need triples(event type, context, action) instead of pairs (event type, action) A context is an object for which an event is interesting (like a particular button) Event type-context-action tables can be implemented, for instance, as hash tables. In Eiffel, this is implemented with agents: agents are objects encapsulating behavior.
The result of this is that we now have two actions:
- Subscribers (observers) subscribe to events
- The publisher triggers an event
This concludes my live blogging of laser, but I will be back very shortly: in two weeks with live blogs of ICSM 2012.