Sign in to follow this  

Arbitrary object deserialization

Recommended Posts

So here is the idea. We have game objects described in XML, such as:

Obviously simplified, but what we do is load this from XML into a Property object. Then the calling code gets this object and can tweak the values easily to make a unique button. Once done, the Property object is passed to a templated function: createObject<Button>(). Then GameObjectFactory creates an object to the specifications and returns it as the correct type. Our only problem is the way in which we currently set the members of the objects being created, currently it is crude and inflexible. It was only intended as a hold over till we could find a better way, so now we are trying to find a better way. Does anyone have any ideas? The factory gets a bunch of "properties" all of the correct data types, but how does it know how to put them into the right parts of this specific class of objects? ====== [edit] So it turns our this is a whole area of study called XML Data Binding, doesn't seem to be a lightweight way of doing it elegantly ATM. [Edited by - Wavesonics on January 29, 2008 4:03:42 PM]

Share this post

Link to post
Share on other sites
It doesn't; the object classes do. Give them a constructor that accepts a dictionary of values and sets its members accordingly. The factory determines the type of thing to instantiate and calls an appropriate constructor, passing it the dictionary that it created by parsing the XML.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this