In my previous post, I modified Robotlegs’ MediatorMap to allow classes that were part of the view, but not necessarily on the display list to be Mediated. This worked nicely in some cases, but this morning I was playing around with the PresentationModel. The big difference between the presentation Model and MVC/MVP is that instead of a passive view observed by the Controller / Presenter, it is the PresentationModel that is ignorant of the view. My previous code didn’t allow for this relationship. It assumed that the interceeding class wanted a reference to the view, but what if it was the other way around?
I solved this problem using a Factory. A simple factory is passed into the InterceedingMediatorMap, along with the Interceeding class (or the Interface the Mediator uses to store its instance). This factory abstracts the wiring up of the view. Inside the MediatorMap, just before the Mediator is created, an instance of the InterceededViewFactory (Yeah I know these names don’t roll of the tongue). The viewComponent instance is passed to it and it returns the interceeding class to be injected into the Mediator. For example in the case of a view that uses the Presentation Model, the factory creates the presentationModel instance and passes a reference of it to the view, then returns it. This way, the Mediator gets its reference to the presentationModel and so does the viewComponent, but the presentationModel remains ignorant of both.
Here is the ApplicationContext:
override public function startup() : void {
//Controller
commandMap.mapEvent(ColourSelectionEvent.SELCTION, UpdateModelCommand);
//Model
injector.mapSingletonOf(IDataModel,DataModel);
//Login View Injection Points
injector.mapClass(ViewModel, ViewModel);
injector.mapClass(ViewData, ViewData);
//Interceeded Mediators
interceedingMediatorMap.mapInterceededView(app.view.components.MVP.View, MVPMediator, MVPFactory, Presenter);
interceedingMediatorMap.mapInterceededView(app.view.components.presentationModel.View, PresentationModelMediator, PresentationModelFactory, PresentationModel);
//Standard Mediators
interceedingMediatorMap.mapView(app.view.components.autonomousView.View, AutonomousViewMediator);
super.startup();
}
I’m going to do some more work on this as there are a few things I don’t like about the way things are set up – too may arguments on mapInterceededView for example, but for the moment, here are the classes, along with two example factories.
Browse Timeline
Comments ( 1 Comment )
[...] Update: I have taken things a bit further along here. [...]
1ndivisible » Making Robotlegs’ Mediation of Views More Flexible added these pithy words on Mar 04 10 at 10:48 am