• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Is encapsulation deprecated in ObjC?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Is encapsulation deprecated in ObjC?


  • Subject: Re: Is encapsulation deprecated in ObjC?
  • From: Charles Jolley <email@hidden>
  • Date: Thu, 16 Aug 2001 13:51:33 -0500

On Thursday, August 16, 2001, at 01:27 PM, Chris Gehlker wrote:
> This is exactly what I was talking about. I'll pick on Apple since they
> are
> big enough to take it. "Learning Cocoa" is full of simplistic setters
> that
> are either not used in the sample code provided or used only in
> messages to
> self. Furthermore, "Learning Cocoa" shows a technique for hiding
> methods in
> the .m file but never applies that technique to those setters when they
> are
> only used for messages to self. I started to conclude from that and a
> few
> other examples that "It's a Cocoa convention to allow any object to mess
> with another objects instance variables." I am quite relived to discover
> that this tentative conclusion was wrong.

BTW, I remember reading some old documentation several years ago stating
that one should create accessor methods for all ivars subclasses might
want to access to help limit the "fragile base class problem." If you
change the implementation of your class in such a way that a given ivar
is no longer used, you can still provide accessors for that ivar that
calculate the value by some other means. Thus, subclasses will "just
work" without having to be modified.

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.

Cheers,
-Charles


  • Follow-Ups:
    • Re: Is encapsulation deprecated in ObjC?
      • From: Chris Gehlker <email@hidden>
    • Re: Is encapsulation deprecated in ObjC?
      • From: Brian Hill <email@hidden>
References: 
 >Re: Is encapsulation deprecated in ObjC? (From: Chris Gehlker <email@hidden>)

  • Prev by Date: Re: == nil vs. isEqual:nil
  • Next by Date: Re: NSBitmapImageRep and drawing with alpha
  • Previous by thread: Re: Is encapsulation deprecated in ObjC?
  • Next by thread: Re: Is encapsulation deprecated in ObjC?
  • Index(es):
    • Date
    • Thread