PureMVC Architects Lounge

Announcements and General Discussion => General Discussion => Topic started by: darnpunk on January 30, 2009, 07:16:10

Title: Proxy to Controllers/Proxy?
Post by: darnpunk on January 30, 2009, 07:16:10
Is it acceptable to send notifications from the proxy that will call a controller? For instance, I have data from a remote proxy and once updated, it affects another proxy without affecting the view yet (until later on).

Let's say ServerProxy and GameStateProxy. Upon receiving an update from the ServerProxy, I need to save the latest game state to a proxy and I created GameStateProxy. From the ServerProxy, I send notifications that calls controllers to update the data.

I was thinking if I were to instead send a notification to a mediator which then sends a notification to a proxy there will be additional steps. Furthermore if there a few mediators using this proxy, which mediator should handle this responsibility? This is why I find that proxy to controller is the easiest way. Is this right?

Is there a rule of thumb on how many proxies one should have in an application (e.g. game) like session proxy, remote proxy, list of character movieclips proxies etc? Should they be compacted into one? How do you handle proxy to proxy communications?


Title: Re: Proxy to Controllers/Proxy?
Post by: Joel Hooks on January 30, 2009, 08:58:13
How do you handle proxy to proxy communications?

I consider my data model to be entwined with itself, meaning I handle proxy-to-proxy communications directly. I have no problems calling an instance of another proxy in my applications data model from any other proxy in the same model.

In terms of how many proxies an application might need... well, that depends on the granularity you want/need to achieve for your purposes. There is no set limit outside of the obvious limit placed on the platform and system resources. For some portions of my model I will store a collection of objects in an ObjectListProxy, with all of the VOs proxied there and only there. Other times, I want a finer grain to my control so I will create the ObjectListProxy as well as creating individual ObjectProxy objects for each of my unique Objects.

You don't need to have a command between your proxy communications, but you certainly can. It is perfectly acceptable to initialize and activate a command from within a Proxy.

Title: Re: Proxy to Controllers/Proxy?
Post by: darnpunk on January 31, 2009, 07:05:34
Thanks for the feedback Joel. Definitely helpful for my case.

I read in one of the threads that adding Commands might add complexity. I am trying to avoid using commands/controllers as much as possible. Unless the commands are reusable or have more than a few lines of codes, I manipulate the data through my mediators.

For example:

  • I receive a game state update (e.g a new user enters room) from the server.
  • ServerProxy sends notification to command or updates GameStateProxy directly.
  • GameStateProxy then sends a notification to mediators of this update.
  • An interested AnimationMediator would probably show an animation of a user entering a room (e.g door open) and sends a notification once animation is completed.
  • A StageMediator upon receiving the notification from AnimationMediator will then grab the required data (e.g. user appearance data) from the GameStateProxy and adds a new character to the stage.

The above sequence is receive update, save updated data and update the screen (being animation first then show new character). Am I doing it right?

Title: Re: Proxy to Controllers/Proxy?
Post by: puremvc on January 31, 2009, 07:40:14
Bada-bing. Perfect.