Re: Private Method?
Re: Private Method?
- Subject: Re: Private Method?
- From: Jens Alfke <email@hidden>
- Date: Mon, 07 Nov 2011 16:03:46 -0800
On Nov 6, 2011, at 2:10 PM, Bryan Harrison wrote:
> I'm reviewing some sample code and am looking at a class with a method declared in @implementation which isn't mentioned in any @interface.
>
> Is this a private method, something else entirely, or merely sloppy coding?
That’s considered a private method. (Unlike in C++ there’s no way to absolutely prevent external code from calling it, but the compiler will give you warnings if you try to do it directly.)
In Objective-C it’s considered good style to have the @interface section show *only* the public API of the class. Internal methods should go only in the @implementation. (If you need a forward declaration you can do that with a class continuation in the .m file.)
This keeps the header more readable and hides the implementation details of the class from view. It also speeds up compilation a bit, and can avoid the need to #import more headers from your .h file.
—Jens
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden