Is encapsulation deprecated in ObjC?
Is encapsulation deprecated in ObjC?
- Subject: Is encapsulation deprecated in ObjC?
- From: Chris Gehlker <email@hidden>
- Date: Wed, 15 Aug 2001 20:16:09 -0700
I've been into ObjC for a few weeks now and am getting to the point where I
can write real programs. There still is one thing that has me scratching my
head. I read the ObjC.pdf paper and in starts out with the standard
discussion of the benefits of encapsulation. Then I started looking at
sample code and there seems to be an ObjC convention of "Lets define public
accessors for all our instance variables."
Now, as I'm sure most of you know, there is a school of OOP typified by the
folks who hang out on com.lang.c++.moderated that makes a fetish of
encapsulation. For those guys the ideal class has no public accessors. I can
hear them saying "Your Objective C program has no objects, just structs."
I can see a readability advantage to all the accessors.
[self setMyVar:newVar] is more self documenting and flows better than
assignment. But that could be accomplished with private accessors.
I also note that the Cocoa frameworks themselves seem to be more sparing
with accessors than most of the sample code I see.
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?
--
Tact is the ability to describe others as they see themselves. -Abraham
Lincoln, 16th president of the U.S (1809-1865)