Re: "Multiple Inheritance" between NSTableView and NSOutlineView
Re: "Multiple Inheritance" between NSTableView and NSOutlineView
- Subject: Re: "Multiple Inheritance" between NSTableView and NSOutlineView
- From: Matt Neuburg <email@hidden>
- Date: Mon, 03 Jul 2006 20:32:35 -0700
- Thread-topic: "Multiple Inheritance" between NSTableView and NSOutlineView
> Date: Mon, 03 Jul 2006 19:26:54 -0700
> From: Jerry Krinock <email@hidden>
> Subject: "Multiple Inheritance" between NSTableView and NSOutlineView
>
> I have in my app:
> XXTableView, a subclass of NSTableView
> XXOutlineView, a subclass of NSOutlineView.
>
> I just wrote a group of methods, with identical implementations that I would
> like to add to both XXTableView and XXOutlineView, without duplicating them.
> It seems there should be a way to do this, but I can't see it.
>
> A category? No, because categories can only be added to one class.
>
> A protocol? No, because protocols are only interfaces, not implementations.
>
> A superclass? No, because XXTableView and XXOutlineView already have
> different superclasses, and Objective-C does not do multiple inheritance.
>
> Is this combined superclass do-able? Or is there some other feature of
> Objective-C I have overlooked that could put these common method
> implementations into both of my existing subclasses?
Don't use is-a; use has-a. Simply give both XXTableView and XXOutlineView an
ivar which you initialize to an instance of the class containing the common
methods. Now both XXTableView and XXOutlineView have the same "helper". And
now use message forwarding to automatically route relevant messages to the
helper. m.
--
matt neuburg, phd = email@hidden, http://www.tidbits.com/matt/
pantes anthropoi tou eidenai oregontai phusei
AppleScript: the Definitive Guide - Second Edition!
http://www.amazon.com/gp/product/0596102119
Take Control of Word 2004, Tiger, and more -
http://www.takecontrolbooks.com/tiger-customizing.html
Subscribe to TidBITS! It's free and smart. http://www.tidbits.com/
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden