PureMVC Architects Lounge

Announcements and General Discussion => Architecture => Topic started by: joao.saleiro on June 17, 2008, 06:59:47

Title: Who should call the delegates: proxys or commands?
Post by: joao.saleiro on June 17, 2008, 06:59:47

I am used to Cairngorm. In Cairngorm, commands use the serviceLocator to get a reference to a service delegate to call a remote procedure. When data arrives, the model is changed accordingly.

It seems that in PureMVC this is slightly different, since proxys should call directly the service delegates. In one hand, I was used to the Cairngorm methodology and I feel comfortable with it. In another hand, I will need less code, and less "confusion", by making the proxy call the service delegate directly.

Which one is the preferable practice?


João Saleiro

Title: Re: Who should call the delegates: proxys or commands?
Post by: puremvc on June 18, 2008, 09:26:56
Hi João,

Though a command could do the work, that would be the Proxy's responsibility in PureMVC.

In Cairngorm you don't have a long-lived class like the Proxy controlling access to each piece of data. You have a static model (ModelLocator) onto which you hang values like decorating a Christmas tree. So, it makes sense to use Commands to do this work in Cairngorm. Something has to decorate the tree so the command sets itself up as a responder via the delegate and handles the result, usually by tacking it onto the ModelLocator.

But in PureMVC, the model (Model) caches Proxy objects, each of which can be as long-lived and intelligent as necessary, to control access to its data object. So in PureMVC, it makes more sense to have a Proxy handle service interaction related to its data object. And actually, it can do this without requiring a Delegate.

If a given Proxy is the only class that will invoke or respond to a given service call there is no need for a Delegate. Only if multiple Proxies will access a given service do you need to add the extra complexity of the Delegate.


Title: Re: Who should call the delegates: proxys or commands?
Post by: joao.saleiro on June 18, 2008, 09:36:43
I like Delegates because I see them as a "copy" of the backend API. With delegates, our client side developers don't need to care about the complexity of the backend.
Also, you can use delegates to translate the backend data format to the client-side data format, if needed.

I am currently implementing the access to the delegates using the proxy, the first time some class needs to access the "data" property of the proxy. Also, I'm making a public function "refresh" to refresh the data if needed. This is way different of what I was used to develop in Cairngorm, where the view was binded to some property on the ModelLocator, and it needed to call some command to get the data on the server-side.
Let's see how it goes...