[plt-scheme] OOP problem - cloning objects
Hi,
I've stumbled over an oop problem that probably has an easy standard
solution but right now I'm confused. I have several subclasses of
MrEd's text% class, like e.g. text% > z-text% > z-entry%.
Now I need to create a deep copy of instances of such classes.
Therefore, I have created an interface clonable-object<%> with a method
clone that is supposed to return a deep copy of the resp. object.
Problem: Each superclass sure knows how to clone itself, but naturally
it can only return an instance of its own class in its clone method.
It would seem natural for z-entry% to rename the clone method of
z-text%, calling the superclass method, cloning any information that
is new to z-entry%, and return a new instance of z-entry%. But the
superclasses clone method will return an instance of z-text%.
Does that mean that e.g. z-entry% has to re-implement all of the clone
code that is already in its superclass z-text%? Is there a simple trick
I've overseen to clone objects such that each derived class only
provides "its own part" to the cloning process? Is there some way to
cast an object into an object of a derived class?
Regards,
Erich