PureMVC Architects Lounge

Announcements and General Discussion => General Discussion => Topic started by: hang on November 09, 2008, 03:08:06



Title: Data Binding Vs. Notification
Post by: hang on November 09, 2008, 03:08:06
Is the use of Flex's data binding something that's encouraged or discouraged?  It's quite convenient to use data binding for simple fields so that when one UI updates the data, all the other UI elements are updated as well.  This, however, seems to tie my code closer to Flex than what would be necessary.  I can see how I can accomplish the same thing with notifications but it can easily get out of control if everytime a field or variable is updated I have to send out a notification.  While I appreciate how PureMVC is not necessarily tied into Flex, the reality of my situation is that my code is tied into Flex and it would be silly for me to not use what is already there.

What are people's opinion on this? 


Title: Re: Data Binding Vs. Notification
Post by: hang on November 09, 2008, 03:48:41
Well, I should have searched more.  This exact question has been answered: http://forums.puremvc.org/index.php?topic=60.0


Title: Re: Data Binding Vs. Notification
Post by: puremvc on November 09, 2008, 03:50:26
Data. Binding is great for wiring inside the black box of a view component. As you mentioned, to fill and collect values in a form.

But you want to bind to an object local to the view component rather than have binding expressions reacing back into the model tier to get the data.

One easy way of handling this is to have a value object that shuttles the data across tiers.

So the model tier retrieves the data, alerts the view and controller tiers by notification. The VO can be passed in the note or retrieved by the recipient. For instance a mediator might be interested, take the vo and set it on a public property of its view component.

Then inside the view component might be marked bindable and have a form getting its data from that vo. And reverse binding tags can also be setup changes to the field update the vo automatically.

Binding expressions are also great inside the view component for things like enabling components conditionally based upon internal state. Like only enabling a button when password is not null and password equals confirmPassword.

This is the stuff that belongs in a view component not in the mediator. It is nitty-gritty, down and dirty, sleeves up and more coffee brewing view implementation. If you migrate the app to another platform this is the part that will absolutely have to be reimplemented, so make it a black box with clear behavioral requirements and adapt that to your more abstract framework based apparatus.

The PureMVC part can port easily, but you have to live with your ui toolkit, but by feeding view components data and then leaving it up to the component what to do with ita mediator will insulate the rest of the architecture from foibles of the view implementation.
Have a look at the Flex EmployeeAdmin demo for examples of binding inside custom components.

Then for fun have a look at the python version which uses wxPyhon ui widgets.

-=Cliff>