Re: Private, Protected methods in Obj C?
Re: Private, Protected methods in Obj C?
- Subject: Re: Private, Protected methods in Obj C?
- From: Andy Lee <email@hidden>
- Date: Wed, 3 Apr 2002 18:17:17 -0500
At 12:14 AM +0200 4/4/02, Ondra Cada wrote:
On Thursday, April 4, 2002, at 12:04 , Jonathan Wight wrote:
Static functions should be used inside a class only as a method of last
resort. If you use them you sacrifice all of Objective C's dynamic
loveliness. Dont do it. If you need (mostly) private methods put them
inside their own hidden categories.
I guess one of us two does not know what a "private method" is
(might easily be me -- I have never been an expert in those C++
thingies!). Anyway:
- is it inheritable?
- is it overridable?
I guess twice nope.
You are right on both counts, at least the way Java defines
"private." I don't remember about C++.
A *private* method -- or what I understand a private method is --
is really nothing but a static function, in C++ with a convenient
access to properties. NOTHING MORE (or is it?).
The only "MORE" I can think of is access to the "super" keyword.
Since no dynamic loveliness is *POSSIBLE BY DEFINITION* with a
private method, why should we care in the implementation?
We might care if we're really paranoid about accidental overriding of
the method. Using real Objective-C methods, a sufficiently weird
method name would give almost perfect but not theoretically perfect
protection against accidental overrides. Using static functions, we
don't have to worry; you can have the same static function name in
two different files.
We might also care if we really, really don't want people poking
around our class and calling undocumented methods that we really,
really want to keep private. Again, a person this paranoid would
actually prefer static functions to pseudo-private (or I should say
pseudo-protected) Objective-C methods.
Don't take me wrong: I *DO* advocate using the dynamic runtime
whenever appropriate
Me too. I even use the dynamic runtime, i.e., Objective-C methods,
for my "private" methods, despite the minor risks, mainly because of
a vague sense of aesthetics (I love those spiffy Smalltalk-like
method signatures, for one thing), so I do agree with Jonathan to
some extent.
--Andy
_______________________________________________
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.