How to move logic from Mediator to a Command?

Gert-Jan van der Wel

11 Oct, 2011 09:41 AM

Hey everyone!!

I'm kinda new to Robotlegs. I think I got the basics down, but I
need a bit of help with the following situation.

I have two views. One view (GlassView) catches all mouse and
gesture events and its mediator sends those to the shared
eventDispatcher. The mediator of the other view (SceneView) listens
for the events, does some math and updates its view.

I have a feeling that the mediator shouldn't do the math and I
want to be able to undo the action. So I think I should use a
Command, but how would it work then?

I think that your feeling is correct. It is better to map the
events which are coming from GlassView to a command. Do the
calculations there and then dispatch another events which should be
handled by the ScrenView's mediator and update the SceneView.

Or just move the calculations to the SceneView. View logic is
meant to be in the view, there's no rule against having complex
calculations in views. As long as the outcome of those calculations
isn't used anywhere else, not even in other views, then there's no
problem. Obviously if you're creating a very view-centric app, a
game for instance, then the view data is possibly
application data and then it would be appropriate to extract it out
of the view.