• 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: Private methods in ObjC
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Private methods in ObjC


  • Subject: Re: Private methods in ObjC
  • From: eHolley <email@hidden>
  • Date: Wed, 25 Feb 2004 08:57:20 -0700

Glen,

Keeping in mind that Objective-C's runtime allows ANY object, whether part of your framework or not, to inspect your class to discover all possible method invocations, private methods are designed to keep implementation details away from users (meaning other programmers). The intent is not to make them secret, but to hide complexity. This being the case, you have a few options. One is to document the interface with "don't touch!" comments. ;) (I thought you'd like this.) Another is to leave them out of the interface entirely, and only implement them, keeping in mind that they should then be properly forward-documented.

The approach I prefer is to design the interface with categories or protocols in one of two ways--there are undoubtedly more ways if you thinks about it. If you prefer the user to interact solely with front-methods and hide all backside implementation and variables, define your class accordingly targeted for you, then publish a category or protocol for the user to operate from. Thus you give them an interface to work with without all the baggage. Another design technique is to encapsulate specific functionality within categories that are known only to you, or that are not directly referenced from the user's version of the header files.

Again, the runtime lets all of us see each other's long list of methods, private or not. To goal is to simplify the user's interface while hiding the complexity.

-Erik



On Feb 25, 2004, at 5:48 AM, Glen Low wrote:

Dear All,

I note there's no direct way of making your ObjC methods private to clients. What's the usual idiom for doing this?

1. Define a category on the object and put it into the .m file?
2. Declare methods in the interface but preface them with something?
3. Don't declare the methods in the interface, but simply use them from your code. Presumeably then you have to define those private methods first in the .m implementation before you call them?
4. Put comments like "don't touch!" -- just joking...
5. Any funky techniques like multiple interface declarations?

Cheers, Glen Low


---
pixelglow software | simply brilliant stuff
www.pixelglow.com
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


  • Prev by Date: Re: Line numbers in IDE
  • Next by Date: Re: Cocoa Doc App and AppleScript Studio Support
  • Previous by thread: CFPreferences and byhost preferences
  • Next by thread: RE: Private methods in ObjC
  • Index(es):
    • Date
    • Thread