Re: Private Methods
Re: Private Methods
- Subject: Re: Private Methods
- From: Adam P Jenkins <email@hidden>
- Date: Fri, 22 Feb 2008 09:08:48 -0500
On Feb 22, 2008, at 6:48 AM, Rob Petrovec wrote:
Lack of private methods is a serious flaw in Obj-C IMO.
This is silly. Private is really just about as voluntary in C++ as it
is in ObjC. If a user of your class wants to ignore your decisions
about what should be private methods, they have only to write:
#define private public
#include "yourclass.h"
#undef private
void foo() {
YourClass obj;
obj.aPrivateMethod(); // no compiler errors or warnings
}
So declaring things private in C++ is just an advisory to users of
your class that certain methods and fields aren't intended to be used
by clients of the class, it's not meant as any kind of security
mechanism. In ObjC you can achieve the same thing by not declaring
methods in the interface file, so if a user of your class still finds
out about the method somehow and calls it, they'll get a compiler
warning and will know they're doing something not intended by the
class's author.
Note that this is in contrast to Java or C#, which run in managed
environments, and where private really can be used to fairly securely
block certain methods and fields from being accessed, when using the
correct security settings in the VM.
That said I do agree that it's nicer to have a formal language
construct for specifying what's private, like in C++, than the ad-hoc
mechanisms available in ObjC. I just don't agree that it's really a
serious flaw, more of a minor flaw.
_______________________________________________
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