Re: Mutability
Re: Mutability
- Subject: Re: Mutability
- From: Gregory Block <email@hidden>
- Date: Thu, 22 Nov 2001 09:59:09 +0000
On 21/11/01 1:57 pm, "Ondra Cada" <email@hidden> wrote:
>
NSArray *checkAndChangeIfNeeded(id array) { // OS X, clean but terribly
>
ineffective
>
...
>
if (some_condition) { // need to change
>
array=[[array mutableCopy] autorelease];
>
[array addObject:...]; // or insertObject or whatever...
>
}
>
...
>
return array;
>
}
Shouldn't this be behavior *of your array object*, surely, and not of a
procedural call in some object that clearly isn't responsible enough for the
object's data to know what it actually contains?
If this was being encased properly in the first place, I'd argue, the whole
question would be moot, wouldn't it. Why isn't checkAndChangeIfNeeded:
being called on a NSThoughtIWasn'tMutableDidn'tYouArray? And how does
encapsulation of the data not solve this problem?