Re: Merging a an Objective-C class with other classes
Re: Merging a an Objective-C class with other classes
- Subject: Re: Merging a an Objective-C class with other classes
- From: glenn andreas <email@hidden>
- Date: Tue, 23 Jan 2007 11:58:34 -0600
On Jan 23, 2007, at 11:27 AM, Mark Alldritt wrote:
Hi All,
I have a number of view classes. Each inherits from a different
NSView
class (i.e. NSView, NSOutlineView, etc.). I what to share a common
implementation of cut:, copy:, paste: and other methods across all
these
classes.
An Objective-C Category on NSView does not seem appropriate because
I don't
want to replace the implementation of cut:, copy:, paste:, etc. on
*all*
NSView instances in my application.
I've made a category in the common base class (in your case, NSView)
with unique method names such as "myCommonCopy:", and then had a
small set of boilerplate methods such as:
- (void) copy: (id) sender
{
[self myCommonCopy: sender];
}
You can then either include those simple forwarding methods
explicitly (copy & paste in your source code) if you want to have
some sort of selective control (allowing some things to do copy, some
to do cut, some to do both, for example), or put that boilerplate
into its own file which is then included inside the implementation.
Alternately, you could define a new class with all of these methods,
and then at run time use the various runtime routines to walk the
method list for that "mix in" class and add all of those methods to
your existing classes.
Note that all of these approaches have problems if any of your
methods require adding instance variables (since those instance
variables would be at a different offset for the different classes).
Glenn Andreas email@hidden
<http://www.gandreas.com/> wicked fun!
quadrium2 | build, mutate, evolve, animate | images, textures,
fractals, art
_______________________________________________
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