Re: Writing a protected method in Obj-C
Re: Writing a protected method in Obj-C
- Subject: Re: Writing a protected method in Obj-C
- From: Chris Hanson <email@hidden>
- Date: Thu, 18 Sep 2003 16:46:08 -0500
On Thursday, September 18, 2003, at 04:22 PM, Umed Zokirov wrote:
How can one write a protected method in Obj-C, I mean protected in
sense of C++ protected member function.
What do you hope to achieve from this? In Objective-C you can send any
message to any object at any time. Period. That's how the language is
defined and how the run-time works.
If you don't want classes outside your own to know about a method, just
don't declare it in the publicly-visible header. It's trivial to put a
category with your "private" methods in your implementation file
(MyClass.m):
@interface MyClass (PrivateMethods)
- (void)privateMethodOne;
- (void)privateMethodTwo;
@end
@implementation MyClass (PrivateMethods)
// etc.
@end
And the compiler will emit warnings if you try to send the messages
corresponding to those methods in files other than the one containing
MyClass. It'll still let you send those messages, and the runtime will
still invoke the same methods, but you will get a warning.
The runtime does not and should not support C++-style access control.
It would significantly complicate both the language design and runtime
behavior, and for that it would buy you almost nothing.
-- Chris
--
Chris Hanson, bDistributed.com, Inc. | Email: email@hidden
Custom Mac OS X Development | Phone: +1-847-372-3955
http://bdistributed.com/ | Fax: +1-847-589-3738
http://bdistributed.com/Articles/ | Personal Email: email@hidden
_______________________________________________
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.