Re: Is encapsulation deprecated in ObjC?
Re: Is encapsulation deprecated in ObjC?
- Subject: Re: Is encapsulation deprecated in ObjC?
- From: Chris Gehlker <email@hidden>
- Date: Thu, 16 Aug 2001 09:59:31 -0700
On 8/16/01 8:08 AM, "Brian Hill" <email@hidden> wrote:
>
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).
Point taken.
>
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.
Thanks for the detailed reply, Brian. I noticed that your reply focuses on
methods more than instance variables, though private headers could certainly
introduce both. The conventional explanation of encapsulation focuses more
on instance variables. Are you saying that it's more important to
encapsulate methods than data?
--
When I was a boy I was told that anybody could become President. Now I'm
beginning to believe it. -Clarence Darrow, lawyer and author (1857-1938)