Re: Is encapsulation deprecated in ObjC?
Re: Is encapsulation deprecated in ObjC?
- Subject: Re: Is encapsulation deprecated in ObjC?
- From: Brian Hill <email@hidden>
- Date: Thu, 16 Aug 2001 14:14:09 -0500
On Thursday, August 16, 2001, at 01:51 PM, Charles Jolley wrote:
Since these accessors are for subclasses to use, they cannot be
privatethough you could create a separate category that would be
imported only by subclasses. When used in this manner, accessors
actually support encapsulation, not only among unrelated objects but
even among subclasses. I have found this concept to be very useful!
I haven't looked much at the key/value protocol, but it sounds like that
changes the rules on this topic. However, "Learning Cocoa" is just an
update of several old NeXT tutorials, so this may be the historical
reason for including those methods in the example apps.
Actually, if you know to do it, there's an even simpler way of making
key value coding 'encapsulation-safe' than I mentioned earlier by
implementing:
+ (BOOL)accessInstanceVariablesDirectly;
in your class and returning NO.
Key value coding normally looks for accessors first in various
permutations (ie., -(id)myIvar, -(id)getMyIvar, -(id)_getMyIvar, etc...)
and if and only if it can't find a method that matches and
'+(BOOL)accessInstanceVariablesDirectly' returns YES will it start
digging around in the isa member to get or set the instance variable
directly.
Brian
email@hidden
http://personalpages.tds.net/~brian_hill
___________________________________________________________
"Why? I came into this game for adventure - go anywhere, travel
light, get in, get out, wherever there's trouble, a man alone.
Now they've got the whole country sectioned off and you can't
move without a form. I'm the last of a breed."
-- Archibald "Harry" Tuttle, Rogue HVAC Repairman
___________________________________________________________