Unrelated Epiphany

Wednesday December 22, 2004
Warning: Deep Nerd Zone

I was thinking recently about Imagination, and the problems that I was having with event propagation, and collect() as the kernel.being problematic because of the need for constant re-collect()ing, which is re-executing an expensive tree-walking algorithm.

Then I realized: the solution is basically correct, but should be inverted. collect() illustrates the correct mediator/observer relationship, but is broken in the face of complex event hierarchies. Well, even simple ones, given that the one exposed by "look" and a stateful UI is fairly "complex" by these standards. The real design I'm trying to get to is an observer-based model with mediated observation. In other words, when an object arrives at some point in the object graph, it sends out tendrils looking for all the interfaces to its external environment and asks to be notified of changes in that direction / through that mediator.

Back to our favorite example. A glass box publishes an "external" mediation factory and an "internal" mediation factory. External things register an observer on the external mediator. Internal things register an observer on the internal mediator. These mediators are aware at all times of whatever objects they can access, so collect() isn't necessarily an expensive, arbitrarily-complex graph-walk; the edges of the graph are pre-defined, mediators aren't constructed on the fly, and there is some structural notion of containment so that you can iterate the items that your mediator presents as available without worrying about random changes.

The collect() interface remains available for when it's convenient, such as automatically locating targets and tools for actions, but we lessen the focus on it so that actors can also be stateful observers instead of simply making periodic requests of the model. Now all I have to do is think of names for the methods involved.

I hope that there is at least one person in the world who understands what all of those words that I just typed mean, in that order that I typed them.