views:

296

answers:

2

I've just recently learned the PureMVC framework, and am a little confused as to the coupling between Proxy and Mediator objects. The links on this page connect to some documents describing the framework. (Please note, the links on the aforementioned page open PDFs.)

The diagrams and examples of PureMVC I've examined often show a direct coupling between a Mediator and Proxy. When the proxy's state is updated, rather than sending a new Notification, the Mediator (which retrieves a reference to the Proxy from the Facade) has its state updated.

This certainly seems to simplify the logic of the code, but it also directly couples two seemingly disparate components together. To my understanding, a Mediator's purpose is to translate Events from a view into PureMVC Notifications. Proxies are meant to perform some function to gather data and relay it back to the view. These two components seem to exist in different layers of the application, and perhaps shouldn't necessarily be coupled together.

Wouldn't it make more sense to have the Proxy objects send their own Notifications when their state updates, which are forwarded to the interested Mediator by the Facade?

+1  A: 

Even if you update the mediator through notifications it would be coupled to the proxy but that's ok, it has to be.

As long as you don't couple the proxy i would say it's ok.

Juan

Zárate
Sorry, I don't understand. If the Mediator receives a Notification from the facade (which was sent by the Proxy), and it contains a data object which is used to update the view, how is it coupled to the Proxy? Do you mean they are indirectly coupled through the Notification?
bedwyr
Sorry, the comment before isn't very clear.What I mean is that mediators are always coupled to the proxies if only because they have to represent what's "inside" of them. Views in general "need to know" about models. To me there's no big difference between updating a view/mediator through notifications or updating it through direct access to the proxy (using the facade).As long as it's not the other way around (the proxy needs to know about the mediator), I think it's ok.Hope this makes a little bit more sense!Juan
Zárate
Actually that does make more sense -- thanks. I was reading through some posts in the PureMVC forums, and this subject appears to have a number of different opinions, many of which are pretty rabidly held. Thanks for your thoughts!
bedwyr
+1  A: 

Wouldn't it make more sense to have the Proxy objects send their own Notifications when their state updates, which are forwarded to the interested Mediator by the Facade?

Yes, this is exactly what needs to happen. PureMVC is simply a Notifier / Observer pattern implementation with a lightweight MVC structure linked by a Facade. I strictly advise not to couple Proxies to Mediators; only allow Mediators to respond to Notifications that are sent by the Proxy when the data state changes. This allows those classes to be fully decoupled.

If you are using Flex, I would recommend HydraMVC / HydraFramework which is a Flex-specific port of PureMVC MultiCore, mimicking the API of PureMVC however is much less verbose, and includes a way to decouple server interaction from Proxies via a DelegateRegistry. (Full disclosure, I am the principal developer on this project, however it is fully OSS and free to use / contribute.) Regardless which MVC framework you implement, I still strongly recommend fully decoupling Proxies / Mediators via Notifications.