views:

455

answers:

1

Hello!
I have some small problem in understanding Value Objects in Flex... I'm trying to get some data from PHP/MySQL and send it to Flex but I'm stuck in some (obviously) basic problems...

Let's say That my object in Flex would look like this:

package some.package.VO {

    [RemoteClass(alias="VOPerson")]

    [Bindable]
    public class VOPerson {
        public var personID:int;
        public var firstName:String;
        public var lastName:String;
        public var personDetails:Array;
    }
}

In my case, personDetails is an Array, and in theory, it could be some other object... But is it really necessary to make it an object? I do not intend to use that data nowhere else except within my VOPerson class. It is some associative array, and I can easily transform it to another object, but there will be lots of similar situations in my app, so I would like to avoid making unnecessary (value) objects if there is no need for it...

Anyway, any tip/hint/link about my problem would be really appreciated! :)
Thank you very much!

+1  A: 

I'm not as familiar with PHP/Flex serialization as I am with Java/Flex, but I believe the same principles will hold. If personDetails is an array of primitives, it will be serialized as such by Flex. If personDetails is a type that Flex does not know how to serialize (i.e. you haven't defined it as a RemoteClass), it will be converted to an anonymous object.

If you're trying to prevent personDetails in your PHP code from being serialized to Flex in the first place, that might be more tricky. I know that Flex identifies serializable fields in Java by looking for a public getter/setter pair, so you can prevent serialization by simply not exposing a getter and setter. There might be some similar trick you can do in PHP.

Erich Douglass
Thanks for this great info! Just to ask, is there a need to serialize personDetails in my example, or is it OK to go with primitives? As I mentioned, personDetails is nothing else but simple associative array and it would be used only as a part of a person class, I won't use it as a separate class/object... Thanks!
errata
The only advantage to putting personDetails in its own class would be if you want to add instance methods to it or pass it as a typed parameter to a method. If you don't need this functionality, keeping it as an array of primitives would be less work.
Erich Douglass
Thank you very very much! :)
errata