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 10:08:18 -0500
On Thursday, August 16, 2001, at 09:47 AM, Lloyd Sargent wrote:
I'm not going to argue one way or the other, but apparently in the OOP
community there are two camps: one that likes public accessors and
others that don't. Personally, I learned that the point of OOP was that
you TOLD and object to do something (what I think of as 'active') vs.
setting/asking it for its contents (what I think of as 'passive').
However, sometimes that doesn't always fly. For example, how do I
determine if a button is in a particular state? Uh, er, I guess I have
to ask it for it's value <shuffle's feet and whistles tunelessly>. :^)
The problem is that sometimes ya' gotta have public accessors, IMHO.
Another point I'd emphasize is that sometimes what looks like public
accessors in Cocoa aren't really accessors at all (in the sense that
they just give up the value of an instance variable).
For example, the 'objectValue', 'intValue', etc... methods on various
NSControls really don't just return the value of the instance variable
named 'objectValue'. They wrap a reasonably complex code path going down
into the internal NSCell instance and then the NSFormatter (if there is
one).
So what's going on. Did experience teach that data hiding isn't all
that
important or have I just looked at a biased sample?
No, data hiding is still important.
Far more than in C++ and Java, method encapsulation and such is commonly
done via things like private categories and private header files in ObjC
Cocoa. In many frameworks I've worked on, I have a
'ClassName-PrivateExtensions.h' header for several of the framework
classes that is imported into the implementation of other classes in the
framework, but isn't published as a public header. That way I can have a
whole set of methods (and even helper classes) that are used internally
by the framework but aren't published in 'end-user' (of the framework)
versions of the header files.
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
___________________________________________________________