[Newbies] Object copyFrom: [was: Object clone]

Klaus D. Witzel klaus.witzel at cobss.com
Tue Jan 15 19:26:48 UTC 2008


Hi Jakub,

on Tue, 15 Jan 2008 18:29:53 +0100, you wrote:

> yeah a, b instance of same class and i want copy all instance variables
> values to a i want do a := b but i dont want to a is same object as b. In
> memory will be two objects a, b with same values ..

If you mean to have class Person and (aPerson := Person new), (bPerson :=  
Person new) and later you want that aPerson has exactly the same instance  
variables as bPerson, then you might want

  aPerson copyFrom: bPerson

This is not often used (it's rather at the system level), because most  
Smalltalk developers set instance variables by mutators, like

  aPerson name: bPerson name.
  aPerson address: bPerson address.
  ...

See also the comment in #copyFrom: on the instance side of Object.

Enjoy Smalltalk :)

/Klaus

> but if i change a i dont
> change b.
>
> regards
>
> 2008/1/15, Mathieu Suen <mathk.sue at gmail.com>:
>>
>> Hi Jakub
>>
>> I don't really understand your question.
>> What is a and b? Are they instance of the same class?
>>
>> On Jan 14, 2008, at 10:42 PM, Jakub wrote:
>>
>> > hello,
>> >
>> > i want do i want set var a as all instance vars of b. Something s
>> > clone - coppy of one object. I look for clone command in SBE book
>> > but i found nothing.
>> >
>> > Thnx.
>> >
>> > --
>> > Jakub. _______________________________________________
>> > Beginners mailing list
>> > Beginners at lists.squeakfoundation.org
>> > http://lists.squeakfoundation.org/mailman/listinfo/beginners
>>
>>         Mth
>>
>>
>>
>> _______________________________________________
>> Beginners mailing list
>> Beginners at lists.squeakfoundation.org
>> http://lists.squeakfoundation.org/mailman/listinfo/beginners
>>
>
>
>




More information about the Beginners mailing list