A simple question: How to copy the instance variables of an
object to another - already existing - object
Bert Freudenberg
bert at impara.de
Sun Jul 31 20:20:55 UTC 2005
Am 31.07.2005 um 21:35 schrieb Rudi Bichler:
> Hi,
>
> I need some kind of copyTo: functionality, which copies a complete
> object (i.e. all instance variables) to another object. I need this
> to "convert" an object of class A into an object of a subclass of
> A. Something like:
>
> Object subclass: #MyClass
> instanceVariableNames: 'var1 var2' ...
>
> MyClass subclass: #MySubcl
> instanceVariableNames: 'var3' ...
>
> MySubcl class >> newCopyFrom: original
> "create an object of class MySubcl with is - as MyClass - identical
> to original"
>
> An example of such a functionality is FormCanvas asBalloonCanvas.
> This method is implemented by creating a BalloonCanvas and
> initializing it "by hand". I am looking for a generic way -
> something like copy in Object. Any idea?
Looking into the #copy method in Object you'll notice it calls
#shallowCopy, which implements a generic copy of all instance
variables - take a look!
- Bert -
More information about the Squeak-dev
mailing list
|