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: Basic data type to Strongly typed VO via Proxy or command?  (Read 6753 times)
Roustalski
Jr. Member
**
Posts: 13


View Profile Email
« 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?
« Last Edit: May 05, 2009, 07:43:19 by Roustalski » Logged
Joel Hooks
Courseware Beta
Sr. Member
***
Posts: 146


baby steps

 - 46288188  - passport@provinsal.com  - joeltuff
View Profile WWW Email
« Reply #1 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.
Logged

http://joelhooks.com - my ramblings about developing with actionscript and python using pureMVC and django respectively.
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #2 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>
Logged
Pages: [1]
Print