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: Smart VO  (Read 15275 times)
Sammi
Courseware Beta
Full Member
***
Posts: 45


View Profile Email
« on: May 31, 2010, 11:53:08 »

Hi,

I am looking into this Smart VO concept and I like it.  I have a few questions just to clarify things and it would be great if someone could share his experience/knowledge.

I usually have many Proxies that just have an XML document as data. Until now I have simply added getters and setters in the proxies to give PureMVC actors typed access to the xml.  I don't find it too bad but I do understand that a smart vo has benefits.  Especially for the views - I think.

Is it true that the main benefit is that the vo could be thrown at a view and the view then has typed access to the data?  Obviously the views have not had access to my getters/setters in the Proxies so code has been required to push the data into variables on the view - and to pull them back.

Since a VO isn't a core PureMVC actor it is fine to have the views import them and use and that simplifies the code...

... to push the data to the view
... to pull the data from the view again
... to have typed access to the xml doc

Am I right, almost right, wrong or even terribly wrong?

Best,
Sammi
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #1 on: May 31, 2010, 01:41:48 »

Thats it exactly. Passing XML around is not good, because you have to spread the knowledge of what the implied schema is around to every class that needs it. Bad juju because changing the XML schema now requires all sorts of changes to the code that handles it throughout the app.

And passing references to the Proxies into the views is not good, as it ties the views to the framework and makes them less reusable outside the framework.

VOs (or TOs - transfer objects) are intended as data carriers to shuttle typed data across tiers. And since ActionScript allows for implicit getters and setters, this lets you easily expose typed access to the XML data to any actor in the system including the views. If you ever wanted to extract a view component and use it in another app, PureMVC or not, you could easily repackage it and the VOs it needs and use them anywhere.

-=Cliff>
Logged
Sammi
Courseware Beta
Full Member
***
Posts: 45


View Profile Email
« Reply #2 on: May 31, 2010, 02:19:44 »

Super!

Thanks.
Logged
Sammi
Courseware Beta
Full Member
***
Posts: 45


View Profile Email
« Reply #3 on: June 01, 2010, 03:07:59 »

Hi,

How stupid can I be?  I have been converting my code to use smart vo and thought I was doing ok.  My vo's have getters/setters for elements in the XML and the views have typed access to them.  But then....

Ooops - my getters are returning XMLList in many cases.  That can't be good because then the views have to know the structure of the xml - so the smart vo aren't really solving anything.

Should I go ahead an make vo's for each item in the XMLList and return them as vector or something to the view?  Seems a lot of work and a lot of VO's.

In one particular case I have a NavigationProxy where it's data is an xml document with all navigation items as well as some properties regarding the navigation.  The Proxy instantiates a NavigationVO that has getters to access the nodes and one is to actually get all the navigation nodes for a particular level for the view to iterate over and render.  Currently I am returning it as an XMLList ;)

Should I have that getter return a vector of NavigationItemVO for an example?

Seems like I would be creating a lot of vo's.  Basically a vo for every type of node that I am currently return as lists.

Best,
Sammi



Logged
jpwrunyan
Sr. Member
****
Posts: 84


View Profile WWW Email
« Reply #4 on: June 01, 2010, 05:19:41 »

I have a similar situation.  In some cases I have "sub" VO's for items deeper in the hierarchy that are still complex and frequently used.  Other times I just return the xml node and work directly with it.  In my case, if around >n classes use the same piece of data then I make a sub-VO for it and have the smart VO wrap the xml node in it when it returns the data from some getter.  In my case, n = 4.

I don't think there is anything to worry about.  Do what makes sense.  Smart VO is not a PureMVC specific concept.

If your application is complex, it will have a lot of VO's.  Still better that than editing XML references all over the place, right?
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #5 on: June 01, 2010, 05:32:06 »

Yes, absolutely create all the VOs. It may look like a lot of work, but I guarantee it won't be as much work as trying to debug untyped XML. Or refactor all your XML handling code when you change your XML schema. And once you have it all typed and begin doing stuff with it, 'future you' will thank you profusely for having done it. E4X is great, powerful, awesome and almost as good as beer, but it will drive you bonkers once you've littered your application with it. SmartVOs let you do all that funky magic (even adding search methods) but in one place.

The goal is to hide the XML from your app the second it comes in the door (i.e. service result coming into a proxy). Of course, you can pass anything via notification from the proxy to the mediator or a command, that's a given. But once the data reaches its destination, you need to cast it to the expected data type and work with it in that form. That's where the compiler and your IDE can help you catch problems that you'd otherwise not be able to find out about until it explodes at runtime.

-=Cliff>
Logged
Sammi
Courseware Beta
Full Member
***
Posts: 45


View Profile Email
« Reply #6 on: June 02, 2010, 01:52:54 »

Thank you.

I am creating VO's like crazy now and feeling good about it!

Best,
Sammi
Logged
jpwrunyan
Sr. Member
****
Posts: 84


View Profile WWW Email
« Reply #7 on: June 02, 2010, 03:50:05 »

Thank you.

I am creating VO's like crazy now and feeling good about it!

Best,
Sammi

It's a wonderful feeling. :)
Logged
Sammi
Courseware Beta
Full Member
***
Posts: 45


View Profile Email
« Reply #8 on: June 15, 2010, 09:06:44 »

I was wondering if it is considered "dirty" to have the VO foster more than the XML passed in from the proxy?

In my current case I would for an example want to add a "language" property to my LocalizedLabelsProxy.  All my labels come from an XML document but the selected language does not.

I don't think there is anything wrong with it - but I have been proven wrong more than once ;)

Best,
Sammi
Logged
jpwrunyan
Sr. Member
****
Posts: 84


View Profile WWW Email
« Reply #9 on: June 15, 2010, 06:14:06 »

I'm not sure yet exactly what you mean.  Does one single VO instance hold multiple XML objects that come individually from separate proxies?  If this is the case, then why not just have one Proxy also gather those various language XML files?  Then you would still have the 1 to 1 relationship between proxy and VO.

Or, just make yet another class (not necessarily a VO) that manages the functionality of "selected language" with the various language VOs.  I mean, you could have a collection object that holds these various language VO's which your application populates upon some Proxy notification.

Anyway, I might be misunderstanding you.
Logged
Sammi
Courseware Beta
Full Member
***
Posts: 45


View Profile Email
« Reply #10 on: June 16, 2010, 04:25:23 »

Hi,

Sorry about the brain tease.  I didn't explain properly.

I think it might be more clear to see an example.  Here is a simplified version of my vo:

:
package site.model.vo
{
    public class LocalizedLabelsVO
    {
        protected var _labels : XML;
        public var language : String = "english";

        public function LocalizedLabelsVO( labels : XML )
        {
                _labels = labels;
        }

        public function getLabel( labelID:String ) : String
        {
                var label : String = _labels.(@id == labelID)[ language ];
        }
    }
}

Notice that this vo has a "language" property - not just the xml data that was passed into it's constructor.

Is there anything wrong with that?

The purpose of the smart vo is to hide the XML structure from the application and to provide typed access to the xml.  Having additional properties in the vo doesn't break that so I guess there is nothing wrong with this method.

When there is a LANGUAGE_SET notification a command updates the language property in the proxy's vo and interested mediators call translate() on their views passing along the vo from the proxy. Then the views can easily be translated.

Best,
Sammi
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #11 on: June 16, 2010, 06:12:26 »

This is perfectly fine and one of the reasons to call this a SmartVO.

-=Cliff>
Logged
Pages: [1]
Print