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: ?? Best Practice Flash Builder 4 Value Objects and View / framework separation  (Read 9719 times)
gohloum
Jr. Member
**
Posts: 16


View Profile Email
« on: January 29, 2010, 02:25:35 »

I've been doing some developing in Flash Builder 4 Beta.  Seems from what I have read and implemented in some projects I am playing with, the new fx:Declarations tag is where you would declare your VO's along with other misc non visual elements. 

So I read on a blog about '10 Best Practices for PureMVC' http://www.websector.de/blog/2007/12/25/10-tips-for-working-with-puremvc/ that VO's, not being actors of the frame work are a good way to react to changes in the model without breaking the rules....   

After reading this and trying to conceptualize a bit of ambiguity from that post it got me thinking about a possible solution to allow the view to react to model updates directly vs waiting on the proxy to send a notification, a mediator or command to process it, and finally update the view accordingly (possible not breaking the rules as the article so elegantly expresses?).

Here's my thought:

In your vo package, define a bindable Value Object class

In your view, declare an instance of the vo in the fx:Declarations tag.  Then bind whatever controls to it, it's properties, etc...

On the proxy, create a property of the VO and have the responder cast the result to the VO property.  Create your getter/setters for it as well.

In the mediator, depending on your style, either access the proxy through the facade and set the VO in the view to the VO on the proxy, or send a notification and let a command do it... Something like:
:
mediator.myView.myVo = proxy.myVo;


So, being of curious mind, I tried this and it did work.  The view's declared VO was set before the data was ever received from the server and I saw the control populate after the data was received.  I did not have to send a notification and notifiy a mediator or command of the data received. 

Would this be 'breaking the rules'?  I do have a couple of scenarios in my projects where an ArrayCollection of data objects may get updated by a new record or a record deleted.  It would be nice to have this wireup between databinding of the control and the proxy just to save some time and code, but at the same time I would not want to paint myself into a corner down the road. 

Any thoughts or advice?

I strip down my example and post the code if I can make time this afternoon.
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #1 on: January 29, 2010, 03:15:12 »

Since you have simply passed over a bindable reference VO, the view and the proxy now hold references to the same object. Relying on this reference being the same will work, but it's not always what you want.

For instance, if you have a VO being edited by the view and the changes are aborted, its best if the view was working with a copy of the object and not the object itself. That way you can discard the changed object, no harm no foul. The original can be retrieved from the Proxy. See the employee editing form on the EmployeeAdminDemo, which binds to a copy of the EmployeeVO.

-=Cliff>

Logged
gohloum
Jr. Member
**
Posts: 16


View Profile Email
« Reply #2 on: February 01, 2010, 07:04:30 »

Hey Cliff,

Thanks for your response.  I will take a look at the employee example this morning.

TJ
Logged
Pages: [1]
Print