Saturday, October 31, 2009

Events - Part 6 (Events Reloaded)

It's time for a confession. I'm afraid that my hiatus was only partially due to life getting busy. A bigger part was that I realized an error in my thinking related to events. Since I'm not inclined to revise history and pretend that I always had things squared in my mind, I'll let you read my older postings for details. I did go back and strike-through all the statements that are now changed (to avoid confusion).

The root of my wrong thinking came to light when I started to implement event bubbling. Until that point, my abstraction of event types seemed to fit. Essentially, each event had an EventType and possibly its own Event class. Both firing and listening for events on an object required that the event be declared on that object. Then bubbling happened.

The problem with bubbling is that the listener is attached to a different object than the object that fires the event. While it makes sense that an event must be declared to be fired by an object, the listener had to be less constrained. But, if the mechanism for listening were tied up with the event type (as I had it) and the event type is not knowable, we reach an impasse.

What I realized was that event handling had to be determined at the object level, not at the event level. So that meant EventType had to be refactored. More precisely, EventType had to go. That caused a bit of rework. And quite a bit of delay.

I think I've got everything put back together now, so I'll try to post a rejoinder on events soon. And post the code to SVN, of course.