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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to