FROM : Jonathan Hess
DATE : Sat Feb 23 23:15:28 2008
On Feb 22, 2008, at 6:08 AM, Adam P Jenkins wrote:
> 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._______________________________________________
If a method is private, why would you ever want to place it in a
public header? I could see a justification for @proected applying to
methods, but it seems much better to just not have the private methods
in the interface at all. Putting a private method in the interface
says "This exists, and you can't use it." If I can't use it, why are
you telling me it is there?
I believe that in c++ the MyClass.h file is the *only* interface to
your class. In objective-c, the MyClass.h file is simply the public
interface to your class. You're free to have more than one @interface
and you are encouraged to use them to declare things that shouldn't be
part of your outward facing public interface.
Things would be best if we didn't even have to put our private
instance variables in the header -
Jon Hess
>
>
> Cocoa-dev mailing list (<email_removed>)
>
> 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/<email_removed>
>
> This email sent to <email_removed>
DATE : Sat Feb 23 23:15:28 2008
On Feb 22, 2008, at 6:08 AM, Adam P Jenkins wrote:
> 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._______________________________________________
If a method is private, why would you ever want to place it in a
public header? I could see a justification for @proected applying to
methods, but it seems much better to just not have the private methods
in the interface at all. Putting a private method in the interface
says "This exists, and you can't use it." If I can't use it, why are
you telling me it is there?
I believe that in c++ the MyClass.h file is the *only* interface to
your class. In objective-c, the MyClass.h file is simply the public
interface to your class. You're free to have more than one @interface
and you are encouraged to use them to declare things that shouldn't be
part of your outward facing public interface.
Things would be best if we didn't even have to put our private
instance variables in the header -
Jon Hess
>
>
> Cocoa-dev mailing list (<email_removed>)
>
> 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/<email_removed>
>
> This email sent to <email_removed>
| Related mails | Author | Date |
|---|---|---|
| Philip Bridson | Feb 22, 12:00 | |
| matt.gough | Feb 22, 12:23 | |
| Mike Abdullah | Feb 22, 12:24 | |
| Jean-Daniel Dupas | Feb 22, 12:28 | |
| Rob Petrovec | Feb 22, 12:48 | |
| Jean-Daniel Dupas | Feb 22, 13:06 | |
| Philip Bridson | Feb 22, 13:16 | |
| Philip Bridson | Feb 22, 13:38 | |
| João Pavão | Feb 22, 13:41 | |
| João Pavão | Feb 22, 13:49 | |
| Philip Bridson | Feb 22, 14:04 | |
| Jean-Daniel Dupas | Feb 22, 14:13 | |
| Adam P Jenkins | Feb 22, 15:08 | |
| Adhamh Findlay | Feb 22, 15:57 | |
| Jean-Daniel Dupas | Feb 22, 16:10 | |
| Corbin Dunn | Feb 22, 17:17 | |
| Jonathan Hess | Feb 23, 23:15 | |
| Adam P Jenkins | Feb 24, 01:41 |






Cocoa mail archive

