Re: Sensible way to extend base class?
Re: Sensible way to extend base class?
- Subject: Re: Sensible way to extend base class?
- From: Jonathan del Strother <email@hidden>
- Date: Wed, 20 May 2009 13:56:07 +0100
On Wed, May 20, 2009 at 1:35 PM, Graham Cox <email@hidden> wrote:
>
> On 20/05/2009, at 10:24 PM, Jerry Krinock wrote:
>
>> I believe a short version of your question is: "How can I get multiple
>> inheritance?" The short answer is that Objective-C does not support
>> multiple inheritance.
>
> Yep. I know that, which is why I'm trying to find an elegant workaround.
>
>>> Any solution I've missed?
>>
>> Re-think your design so that the required ivars can be stored in a
>> delegate. If desired to make it more fool-programmer-proof and reuseable,
>> declare the delegate with an informal or formal protocol.
>
>
> The problem there is that A doesn't have a delegate, and adding one requires
> an ivar... back to square 1.
>
> I'm trying to pretend I don't have access to the source for A, which would
> be the case for a Cocoa class for example. Let's pretend that :) Adding a
> 'delegate' ref would be just about acceptable, though it would be unused
> entirely in the framework that provides the object.
>
One option (and I'm not saying it's a great one) is to add a category
to A, and fake ivars using a global dictionary. The dictionary's keys
would be the object instances (or maybe an NSNumber created from the
instance address), and the dictionary's values would each be another
dictionary containing the instance's fake ivars.
Pretty unpleasant, just throwing it out there for consideration...
_______________________________________________
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