tags:

views:

33

answers:

1
+1  Q: 

Save file format

So we've got an app that needs to save and load its state from disk.

We've got the state in an object currently and that object is being serialized directly to XML with the XML serializer object. I've gone over this with the other developer on the project and he seems to think this is the perfect way to go about it. He asserts that having the model on disc being exactly like the representation in memory is ideal.

I feel that the way the data is saved to disk needs to be decoupled from its representation in memory so that we can modify one or the other without it being a breaking change for the saved format. Not to mention that the XML serializer requires everything needs to be read/write where in the object there may be many cases that need to be read only.

The question is there a best practice in regard to serializing in memory data to XML. Is it better to hydrate your object directly from the XML, or decouple the process by using an objects whose sole purpose is to be feed into the XML serializer?

A: 

It sounds like you are pointing out the negatives of his solution, but not really offering a good alternative.

So either:

a) Use his solution until it doesn't work anymore

or

b) Come up with your own solution that addresses the issues that you pointed out.

One thing that might be worth exploring: you could look at an object database like db4o, which might be able to handle saving/loading of object(s) and most changes you make to the class, but might not be ideal for the case where you want to be able to directly edit the on-disk state (you CAN do it, but you'll have to jump through a few hoops).

mgroves
I do have a solution, use a second object whose sole purpose is to represent the data to be serialized. That way the main object can be more flexible in the way it's data is stored.
Joel Barsotti
Oh I see, you want to use some sort of intermediate object. That could work.
mgroves