PureMVC Architects Lounge

Announcements and General Discussion => Architecture => Topic started by: Roustalski on April 30, 2009, 06:40:37



Title: Basic data type to Strongly typed VO via Proxy or command?
Post by: Roustalski on April 30, 2009, 06:40:37
One of my apps stores some configuration information in an XML file on the local disk.

On startup, a proxy reads in the XML via a delegate and sets it's data property equal to a new configuration dto.

Should it then send a notification with the XML/Dto as the body for a command to load the DTO from the XML, or should the proxy load the dto from the xml as a private method?

What is the best way to go vise versa?

The user is ready to save their information and the proxy is notified that it needs to save the configuration. Should the proxy load the XML from the Dto and have the delegate save it to the local disk, or should there be a command that is passed the Dto/Delegate and the command invokes the save method on the delegate after doing the Dto to XML conversion?

I like the idea of some generic commands with generic Dtos and Generic delegates that are then extended for more specific use cases, and that way the proxies truly are just a way to persist the data and fire commands without really knowing much about the data. Am I on the right track?


Title: Re: Basic data type to Strongly typed VO via Proxy or command?
Post by: Joel Hooks on May 11, 2009, 02:48:12
I always do the conversion from XML to VO inside of the proxy saving the VO on the proxy as the data and place a public getter on the proxy to retrieve the typed VO. The proxy parses the VO and then sends out a message saying that it has finished parsing perhaps with the VO as the body for convenience.

I will also sometimes have an optional property on the constructor of the VO for XML so that it will simply do the parsing there to keep my proxy clean since the XML parsing for the VO is specific to that object anyway. Alternatively I will also create helper classes that do the XML parsing outside of the proxy.

Personally, I don't like passing around XML at all in my systems if I can avoid it.


Title: Re: Basic data type to Strongly typed VO via Proxy or command?
Post by: puremvc on May 12, 2009, 05:54:36
Or you can make a smart VO that takes the XML as a property and has getters and setters that talk to the XML structure.

Here's an example:

:
package com.seaofarrows.musicplayer.common.model.vo
{
   
    [Bindable]
    public class MediaItemVO
    {       
        public function MediaItemVO( xml:XML )
        {
            this.xml = xml;
        }
   
        public function get id():String
        {
            return xml.@id.toString();
        }

        public function set id( id:String ):void
        {
            xml.@id = id;
        }

        public function get name():String
        {
            return xml.@name.toString();
        }

        public function set name( name:String ):void
        {
            xml.@name = name;
        }

        public function get filebase():String
        {
            return xml.@filebase.toString();
        }

        public function set filebase( filebase:String ):void
        {
            xml.@filebase = filebase;
        }

        public function get art():String
        {
            return "assets/art/"+filebase+".jpg"
        }

        public function set art( art:String ):void
        {
            // allow read only property to be bindable   
        }

        public function get icon():String
        {
            return "assets/icons/"+filebase+".jpg"
        }

        public function set icon( icon:String ):void
        {
            // allow read only property to be bindable   
        }

        protected var xml:XML;
    }
}

-=Cliff>