PureMVC Architects Lounge

Announcements and General Discussion => Architecture => Topic started by: Sammi on October 18, 2009, 10:44:56



Title: Thinking about how it is best to Save/Load
Post by: Sammi on October 18, 2009, 10:44:56
Hi,

I am about to start a new PureMVC application and although my question really has nothing to do with PureMVC I am sure many of you have already encountered and solved a situation like mine.

The application is a drawing app. The user has a canvas to draw shapes onto.  The shapes have multiple updateable properties like fill color, line thickness, z-order and so on.  The user must be able to save and load drawings and my question is about how it is best to approach that.

I have made similar stuff in the past and then I have saved each shape's properties into the database making it fairly easy to redraw them when loaded.

I don't want to do that again if things like "class serialization" and/or "byteArrays" would somehow be more appropriate.

How would you save what has been drawn to the canvas? 

In PureMVC I will most likely have a VO for each shape on the canvas.  Would you serialize the value  objects and save them into the database as strings?  What happens if ( and when ) I need to alter the value objects? 

I hope someone here has some experience in this area and would be willing to guide me in the right direction.

Best,
Sammi


Title: Re: Thinking about how it is best to Save/Load
Post by: Sammi on October 18, 2009, 04:01:45
I was thinking it must be a rather bad idea to just serialize the vo's or proxies because it would be very difficult to add properties to the vo's or proxies later on. 

Lets say that in the first 1.0 of the application a BoxVO has a properties a,b and c.  Then in version 1.1 I want to add property d.

After I add the d property, deserialization of the BoxVOs from the database would then fail because of the mismatch. The objects don't match.

Am I right? Or am I misunderstanding the process if serialization and deserialization?

Best,
Sammi


Title: Re: Thinking about how it is best to Save/Load
Post by: puremvc on October 19, 2009, 07:02:13
XML.

-=Cliff>


Title: Re: Thinking about how it is best to Save/Load
Post by: Sammi on October 19, 2009, 07:42:49
Brilliant answer ;)

So I will just have my proxies manage an XML object instead of a VO.

I would store each shape as an xml string in the database or simply store all the objects on the canvas in a single XML object.

The XML object could include the version number used to generate it so that any future versions of the app would know how to convert it to the latest format.

Best,
Sammi


Title: Re: Thinking about how it is best to Save/Load
Post by: puremvc on October 19, 2009, 10:07:36
You can have the best of both worlds if you wrap that XML in a 'Smart VO' for easier handling, strong typing, binding, etc.

See this post for more on the Smart VO concept:
http://forums.puremvc.org/index.php?topic=1222.msg5619#msg5619

-=Cliff>