A simple question: How to copy the instance variables of an
object to another - already existing - object
chaoshierophant at yahoo.com
Sun Jul 31 21:06:53 UTC 2005
Cool. That's I was looking for!
Thanks a lot
Bert Freudenberg <bert at impara.de> wrote:
Am 31.07.2005 um 21:35 schrieb Rudi Bichler:
> 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 -
Start your day with Yahoo! - make it your home page
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Squeak-dev