• Advertisement
Sign in to follow this  

Arbitrary object deserialization

This topic is 3678 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

So here is the idea. We have game objects described in XML, such as:
<GameObject>
  <width>100</width>
  <height>50</height>
  <texturepath>button.png</texturepath>
</GameObject>



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
Advertisement
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
Sign in to follow this  

  • Advertisement