[comp.lang.objective-c] promotion

simsong@media-lab.MEDIA.MIT.EDU (Simson L. Garfinkel) (12/04/90)

Is there any way to change the class of an object?  That is, to change
it from class A to a subclass of A?

................................................................simson

greg@sce.carleton.ca (Greg Franks) (12/05/90)

In article <4252@media-lab.MEDIA.MIT.EDU> simsong@media-lab.MEDIA.MIT.EDU (Simson L. Garfinkel) writes:
>Is there any way to change the class of an object?  That is, to change
>it from class A to a subclass of A?

If you are willing to fileOut and fileIn the object, the answer is
yes.  The technique is a bit tricky, but we have done it here as our
application has evolved.  First, save the object using the old class
hierarchy with fileOut:.  Then, massage the ascii filer record to
correspond to the new definition of the class (the easiest way to
perform this operation is file out an instance of the new definition
of the class then compare it against the old definition).  Finally,
fileIn the massaged version of the object.  Presto... converted object
(we do this operation on-the-fly by saving a "version number" in the
filer output and calling a few methods to automagically massage
records if the saved version does not match the current version).  You
will likely find lots of bugs in the filer :-(.

If you want to mutate an object while the program is running -- I'm
afraid that I cannot help -- we haven't tried to do that (yet :-).

Seasons greetings...

-- 
Greg Franks, (613) 788-5726               | "The reason that God was able to    
Systems Engineering, Carleton University, | create the world in seven days is   
Ottawa, Ontario, Canada  K1S 5B6.         | that he didn't have to worry about 
greg@sce.carleton.ca  ...!cunews!sce!greg | the installed base" -- Enzo Torresi