On Jun 17, 2010, at 8:19 PM, Matt Neuburg wrote:

> On or about 6/17/10 5:56 PM, thus spake "Roland King" <r...@rols.org>:
> 
>> if ... you just have a class variable called <key> or _<key> then the
>> whole array is not replaced, the method you call on 
>> NSMutableArrayValueForKey:
>> is passed through to that underlying variable which does what you might 
>> expect
>> and operates on the array variable directly.
>> 
>> That's not such a rare case.
> 
> In fact it is exactly the case I had in mind. :) That's really just what I
> wanted to hear. Someone asked "how do you think the proxy object works";
> that *is* how I was thinking it might work. Thx - m.

The problem with things like this is the way it destroys encapsulation. It 
absolutely gives me the willies the way KVO can be used to completely bypass 
encapsulation, allowing any object that wants to to read the contents of any 
instance variable — even ones that are declared @private — by using 
valueForKey:, and even to change these ivars (!!!) using -setValue:forKey:.

Yes, I am aware that you can override accessInstanceVariablesDirectly to return 
NO. However, the default is YES, which means that any instance variable for any 
object for which the developer didn’t think to override this method can be 
monkeyed with by any other code running anywhere! The scariest thing is that it 
could even be done accidentally, if someone uses a wrong key by mistake, which 
just happens to be the name of an instance variable!

Long story short, since my hope is that Apple eventually comes to their senses 
and changes this behavior, you’d be safest just implementing the accessor 
methods like you’re supposed to.

Charles_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to