When an event fires that should act on the focused control (not the control that fired the event), how do you handle this in the Model-GUI-Mediator (MGM) pattern? I suspect this question also applies to the closely related MVP pattern if you have more than one model.
I titled this 'delegating events' because I think the mediator for the event-originating control has to delegate the event to the mediator for the selected control (or to its model) - but the question is, 'how?'
Background
The MGM pattern is a bit like MVP Passive View, except that you have a separate 'mediator' for each control (rather than one presenter per form). A control's events are all handled by its mediator, and the mediator calls methods of its particular model in response. The mediator is an observer of the model and updates its control when the model changes. It's particularly suitable in a RAD environment where your controls don't have data binding and you don't want to subclass them. It also has the advantage that there's very little boilerplate code to hook up events, unlike Passive View. Here are two more detailed descriptions:
Problem Example
A form contains a number of controls that provide views on a number of model objects. Only one of these views can be selected at a time. (Imagine a multi-document editor if you want something concrete.)
A user invokes a command from a menu. This calls the Execute method in the particular menu item's mediator object. (The menu item is a control, so it has a corresponding mediator.)
The command is supposed to perform an action on the currently selected control.
So the menu item's mediator needs to find either the mediator belonging to the selected control and delegate the action there, or it needs to find the model associated with the selected control's mediator and call that directly.
But how does the menu item's mediator find the selected control's mediator?
In MGM, mediator objects are supposed to be self-contained, so don't know about other mediator objects. The controls are not allowed to know anything about the models (to maintain clear separation of concerns). The only thing the controls know about their mediators are the event handlers.
Hacky workaround
The best I've come up with so far is to examine an event field in the selected control, which will be an object method pointer to that control's mediator. In Delphi I can cast this to a TMethod and hence extract the object pointer for the control's mediator. I can then cast this to the mediator's type and call the required method.
But this seems to rely heavily on a language feature (TMethod) and also creates dependencies between the mediator classes.
Perhaps I'm on the wrong track entirely…
(P.S. Could someone with more rep than me please create a "model-gui-mediator" tag? Thanks.)