Re: How do I give a set of methods to some objects but not others?
Re: How do I give a set of methods to some objects but not others?
- Subject: Re: How do I give a set of methods to some objects but not others?
- From: Dustin Voss <email@hidden>
- Date: Fri, 24 Nov 2006 12:41:03 -0800
On 24 Nov 2006, at 11:59 AM, Alan Smith wrote:
Protocols:
They would work except I would then have to implement it over and over
again and each implementation would be the same. I want to find a way
to only implement the methods once and then use that one
implmentations.
A cheesy way to do this is: make global functions that implement the
functionality, and then have each protocol implemented to simply call
those globals.
A less cheesy way to do this is: make the formal protocol to mark
which classes adhere to it, but actually *implement* it as an
informal protocol on NSObject or whatever. The informal protocol
implementation can check to see if self adheres to the formal
protocol and throw an exception if not.
A strange & hacky was to do this is: use the Objective-C runtime
functions, specifically, class_addMethods and sel_registerName, to
add the one-and-only implementations of the desired methods to the
relevant classes.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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