copy: self shallowCopy postCopy

Andreas Raab andreas.raab at gmx.de
Wed Oct 19 16:01:19 UTC 2005


stéphane ducasse wrote:
>> TestClass>>postCopy
>>   "Copy a and b"
>>   a := a copy.
>>   b := b copy.
>>
>> If "a == b" before the copy then "a ~~ b" after the copy. In  general, 
>> without providing a context (like DeepCopier) it is  impossible to 
>> treat aliases correctly, so the copying you have here  works only for 
>> the most simplistic structures (pure trees with no  aliases).
> 
> Yes but is it not the responsibility of TestClass to know that a ==  b. 
> Because this is a kind of invariant of the class.

But that's only the most trivial example. Consider this instead:

	a := Array new: 1.
	b := Array new: 1.
	c := Array new: 1.

	a at: 1 put: b.
	b at: 1 put: c.
	c at: 1 put: a.

	a copy.

What now? Do you consider it part of the invariant of Array to know that 
a cycle can be constructed with it (because clearly it can)? And how 
would Array detect and resolve the cycle?

Cheers,
   - Andreas



More information about the Squeak-dev mailing list