Re: Parts of a Method
Re: Parts of a Method
- Subject: Re: Parts of a Method
- From: "David W. Halliday" <email@hidden>
- Date: Fri, 16 Aug 2002 17:30:50 -0500
- Organization: TNRCC
Isaac Sherman wrote:
>
on 8/13/02 1:34 AM, the method -(id)email@hidden:(id)
>
sender:@"Brendon Bruns"; returned:
>
>
> ... And is convertAmount:
>
> atRate: just referring to the name of the method that is called by a
>
> message?
>
>
...
>
As for the second, I think the answer is another yes. But more
>
specifically, it refers to the signature of the method; you could have
>
multiple methods with the name convertAmount, but different arguments (for
>
instance, :(int) amount atRate:(float) rate; or :(NSNumber *) amount...
>
etc.,). This is name mangling, which is the heart and soul of OOP! Not
>
really, just a useful throw off, but still, at the least, a principle of
>
OOP.
Unfortunately, though there is indeed a need to keep the "names" (the selector)
of the methods unique (at the level of the object to which the message is being
passed), there is no reason, other than usability, that the portions of the method
selector have any direct connection with the argument types.
Typically, the parts of the method selector should be chosen such that the
message passed to an object forms something close to a sentence or phrase (this in
the context of text used when the message is passed, as opposed to the method name
prototype). (Incidentally, there would be much less need for multiple similar
methods that differ only in the argument types if Objective-C didn't retain the
primitive/non-object C types.)
Basically, when you wish to think of only the method selector (which is used in
the @SEL() operator) just eliminate the arguments and their types. Therefore, the
selector for the above method prototype is convertAmount:atRate: .
Then the method is invoked via a message such as [someObject convertAmount:
myMoney atRate: presentExchangeRate]. (I wish Objective-C would support more
general method selectors, like SmallTalk, but I know that would be difficult, or
even impossible, to parse along with the myriad of C constructs. However, as a
compromise, I would at least like to see Objective-C permit trailing portions of
method selectors [i.e. "convertAmount:atRate:toNewAmount", though this is not a
great example of its use, just as this method selector is not a great example of my
statement that selectors /should/ be chosen such that the message text reads like a
sentence or phrase].)
>
...
>
>
Take care,
>
>
--
>
Isaac Sherman
I hope this helps. (Go ahead and ask about anything here you don't agree with
or don't understand.)
David Halliday
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.