[Tutor] Changing a class into a subclass
maxnoel_fr at yahoo.fr
Thu Mar 24 19:30:34 CET 2005
On Mar 24, 2005, at 18:07, Ismael Garrido wrote:
> I have a program that saves/loads to/from XML. I have a main class
> Building, and a subclass House(Building). When I save the code I
> instruct each object to save itself to XML (using ElementTree), so
> House adds itself to the XML tree.
> My problem is when I load the XML. Before having subclasses what I did
> was to send the XML object (again in ElementTree) to the object and
> let itself load. Now, with subclasses, if I send the House XML to
> Building I get a Building instance, when I need a House instance.
You can't make an object transform into an object of a different
class. You need to identify what class the object will be an instance
of before loading it. Which, if you're using XML tags like <Building
type="House"> or <House>, shouldn't be very difficult to do.
maxnoel_fr at yahoo dot fr -- ICQ #85274019
"Look at you hacker... A pathetic creature of meat and bone, panting
and sweating as you run through my corridors... How can you challenge a
perfect, immortal machine?"
More information about the Tutor