« dataProvider, setForm(), or whateva | Main | Complex Value Objects as Data Descriptors »

February 05, 2008

My Boring Base Value Object

After some very encouraging remarks from Ark on this post I decided to make my Titles as boring as possible so all the left brain people in the world ( read about them here ) can understand me. If you want to tune out now now I’ll understand.

Or not, I’m really just interested in blogging about technology so I’ll keep to my thought and talk about using a Base Value Object . One of the things I never do is set individual properties on objects. I should be able to pass them an object, and they should know how to set themselves. I demonstrated this with that horribly named  post here, and I wanted to follow up that post with the technique I use to create value objects.

The concept is as follows: You have a lot of different value objects and no matter what you throw at them they know how to populate themselves, so that whether it’s an object returned from the server or it’s a selectedItem from a DataGrid the call to create a new value object should be the same. for example:

var user : UserVO = new UserVO(selectedItem);

var user : UserVO = new UserVO(event.result);

 

My UserVO looks like this. Notice it passes the args to the super function, and it’s only responsibility is to define what it looks like.

public class UserVO extends ValueObject

{

public function UserVO(args:Object=null)

{

super(args);

}

public var name:String;

public var email:String;

}

And finally my Value Object that does all the work.

public class ValueObject

{

public function ValueObject(args:Object=null):void

{

setVO(args);

}

public function setVO(args:Object=null):void

{

if(args == null)

return void;

for (var key:String in args)

{

// for some reason mx_internal_uid gets in the way.

if (key != "mx_internal_uid" && this.hasOwnProperty(key))

this[key] = args[key];

}

}

}

 

My base value setVO function is where everything takes place. You can make your objects dynamic and take out the check for hasOwnProperty(). Also, Examine the type of the args passed in to the setVO function to make it possible to pass in xml, or arrays, or any other sort of data type, I took out my checks for the purpose of brevity.

Well hopefully this post was drab enough to win over Ark. If you’re still in the mood, check out this.

brian..

 

 

 

 

 

TrackBack

TrackBack URL for this entry:
http://www.typepad.com/services/trackback/6a00d8341c046453ef00e55016c0728833

Listed below are links to weblogs that reference My Boring Base Value Object:

Comments

Not bad my friend, not bad. I enjoyed the riffs on Ark the Snark as well. :)

Nice idea! Thanks for sharing.

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been posted. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.

Working...

Post a comment