Re: passing a method name?
Re: passing a method name?
- Subject: Re: passing a method name?
- From: Graham Cox <email@hidden>
- Date: Tue, 22 Dec 2009 09:56:33 +1100
On 22/12/2009, at 4:48 AM, Matt Neuburg wrote:
>> That's what I thought the OP was saying, and I agree. It would mean that doing
> a refactor and changing a method's name, or even adding a new parameter to a
>> method, would break the code in some unrelated method. That's a huge maintenance
>> problem.
>>
> Well, I took the OP to mean just the opposite. Procedures often have to be
> broken into two parts, esp. because of sheets; so, you might start out in
> doMyThing:, but then you show a sheet and after the delegate callback you
> want to proceed to doMyThingPart2:. Since the latter name is derivable from
> the former, passing _cmd is a sensible way to generalize this situation, and
> it's the exact opposite of a huge maintenance problem; provided the naming
> convention is obeyed (a common enough pattern in Cocoa), pairs of methods
> can be introduced or removed at will as development proceeds. m.
On 21/12/2009, at 12:18 AM, Chunk 1978 wrote:
> i have a bunch of methods that will call one method. currently, i'm
> passing a string object so the called method will know which method
> had called it, and complete the proper task based on the method that
> called it.
Well, perhaps the OP would like to clarify what he did mean. It seems unambiguous to me, but sometimes it is hard to make oneself understood when describing code, rather than just posting the code.
Regarding the use of different completion methods based on manipulating some common root name, I think that's a bit strange, misguided even. It's a lot simpler and self-documenting just to declare a protocol, formal or informal, and have the callback conform to that, passing a different target to be called back. That's what Cocoa itself does for sheets and elsewhere, and I follow that pattern as well, on the basis that Apple are leading by example. I've never seen the other approach taken in Apple's code, though if you have a concrete counterexample, I'd be interested to see it.
--Graham
_______________________________________________
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