Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought


Over 10 years of community discussion and knowledge are maintained here as a read-only archive.

New discussions should be taken up in issues on the appropriate projects at https://github.com/PureMVC

Pages: [1]
Print
Author Topic: Proxy and Delegate: Parsing data result, who does it?  (Read 6752 times)
JJfutbol
Sr. Member
****
Posts: 53


View Profile WWW Email
« on: October 29, 2008, 05:44:23 »

I've feel like I have a spot on handle on the view component and mediator relationship but I know I could use some more practice/experience with the C and M portions of PureMVC. I'd like to talk about using Proxies and Delegates and who's responsibility it is to parse the result data and prepare the data for submittal to the service.

At my job we build lots of Flex clients for XML based REST services so we are consuming XML all the time and it does change frequently enough (services having new API versions). I really would like this to be properly handled by a class so I have one place to go to make changes. My problem though is I use both Proxy and Delegate classes and unsure of who's responsibility that is.

I've seen others talk about this in the Cairngorm world but PureMVC is different so the same won't necessarily apply. If I'm exposing methods on a proxy that make service calls, since I use a delegate which hides what type of service is being used should my delegate be handling the result/fault and appropriately parsing the return data? In this case XML. The problem I see with that is now I have so much more work to do as a method on my Proxy will have result and fault handlers and so will my Delegate's equivalent method.

Is this the job of the Proxy class? I guess that would make sense since from reading the docs its meant to hide knowledge of where the data comes from and goes to, from the rest of the application. Delegates are complimentary and not necessary and maybe that's where my error is. Probably seeing this used in Cairngorm is confusing me.

It seemed to me the Delegate class was meant to completely abstract out the service so if you went from an XML service to a JSON one or even to remoting you would only have to change your Delegate class, assuming you are doing your data handling there as well. But maybe this is why we have the Proxy? Was the Proxy meant to take its place?

Hoping for some direction and input. Thoughts?
Logged
Jason MacDonald
Sr. Member
****
Posts: 243


View Profile Email
« Reply #1 on: October 30, 2008, 06:27:11 »

I always keep the parsing of data inside the Proxy, and in my case I use my proxy as the delegate, so everything is encapsulated within the one file. If my services change from XML to Remoting I still need to change roughly the same amount of code, whether it's in a delegate class or proxy, so having it in one place is convenient. I like keeping my model "tight". Meaning a proxy handles the gathering and parsing of it's data and exposes methods to manipulate or request the VO it is responsible for.

I can see delegates handling the parsing being really useful if you had two different service calls that return the same VO. For instances you have an XML service and a remoting service that both return a UserVo. So you could have one proxy handling more than one service that returned the same type of data. But I think a case like that is highly unlikely.

I believe there's a utility, or PMVC enhancement, coming down the pipes that'll allow you to use commands as delegates (likely using some kind of IReponder) so that may open more options as well.

Anyway, this is just my opinion. I think any option is valid if you feel it works best for your code. Whatever you find to be the simplest solution, with the least code, is usually the best.
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #2 on: October 30, 2008, 07:31:49 »

See my last response in this post:
http://forums.puremvc.org/index.php?topic=788.5

-=Cliff>
Logged
Pages: [1]
Print