MVC – Did I Inadvertently Create a Mediator?

designmvc

I'm currently working on my first biggish project. It's a frontend facebook application that has, since last Tuesday, spanned some 6000-8000 LOC.

I say this because I'm using the MVC, an architecture I have never rigidly enforced in any of my hobby projects. I read part of the PureMVC book, but I didn't quite grasp the concept of the Mediator. Since I didn't understand and didn't see the need for it, my project has yet to use a single mediator.

Yesterday I went back to the design board because of some requirement changes and noticed that I could move all UI elements out of the View and into its own class. The View essentially only managed the lifetime of the UI and all events from the UI or Model.

Technically, the View has now become a 'Mediator' between the Model and UI. Therefore, I realized today, I could just move all my UI stuff back into the View and create a mediator class that handles all events from the view and model.

Is my understanding correct in thinking that I have devolved my View as it currently is (handling events from the Model and UI) into a Mediator and that the UI class is what should be the View?

Best Answer

The View should be the code for the UI and the Mediator should handle the events from the View. The Model should be separate from the View and have its "events" handled by a Proxy. Your Mediator can interact with your Proxy, but your Proxy or Model shouldn't interact with your view directly. See the PureMVC conceptual diagram for how things are supposed to interact within the framework.

Related Topic