Ramblings

April 11, 2008

Cairngorm factories for xml in and VO out

Filed under: as3, dev, education, flex, tip — michaelangela @ 5:56 pm

I’ve linked to this article before but I wanted to bring up another point now. I have a good xml data set that is becoming the local store for a chunk of a UI. But because it is xml, it doesn’t update the way it should. I need to try to implement this xml > VO approach, which could yield objects that properly emit data change events. Then the UI can bind more directly which would be very nice.

Flex and Flash Developer – Jesse Warden dot Kizz-ohm » Blog Archive » Cairngorm vs. Joe Berkovitz’s MVCS

It also implies, too, that Factories won’t go away. Neither Cairngorm, nor JB’s MVCS technically have the Factory pattern, but I use it in every single project I do now. Typically this is “throw some XML in, get a ValueObject out”, or JSON, and vice-versa. These are used in Cairngorm’s Delegates, or JB’s MVCS Services. Having a Factory create a nice client side version of our VO’s is very useful, encapsulated, and you end up with easier to read Delegate / Service classes.

To do this though would require something like a hash map. Actionscript 3 doesn’t have it. But some developers have made different versions. I am leaning towards this MultiMap Class though:

H1DD3N.R350URC3 » ActionScript 3 MultiMap Class

Recently I needed a HashMap for a project to map key/value pairs but in
that particular case the Map required to map not just one but several
values to a key. I could have used an array or object to store the
values in and map that one but in practice it turned out that accessing
the map looked rather messy. It would be much more elegant to have a
map to that multiple values can be mapped directly. After some
investigation (strangely even Java seems not to have a MultiMap
included) I came up with writing my own MultiMap class, so here it is!

The MultiMap is heavily based on Michael Baczynski’s HashTable class but I modified it to my requirements and added a couple of additional methods for luxury.

But the updated HashMap is apparently bindable which is what I want. I don’t think the MultiMap is bindable

Eric Feminella: Solutions Architect, Rich Internet Applications » Blog Archive » AS3 HashMap for Flex 2

Additional explanation: The code above is basically the same HashMap, but it is bindable. You will need it i.e. if you want bind GUI components to the HashMap.

Ah yes I see it now. The HashMap implements an IMap which returns an IList when you call getEntries. And that IList has a collectionChange event “Dispatched when the List has been updated in some way”. Flex collections tend to do that which is good for binding.

Advertisements

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: