Re: Forwarding to mimic multiple inheritance
Re: Forwarding to mimic multiple inheritance
- Subject: Re: Forwarding to mimic multiple inheritance
- From: Marco Scheurer <email@hidden>
- Date: Wed, 28 May 2003 16:16:25 +0200
On Wednesday, May 28, 2003, at 03:39 PM, Drew McCormack wrote:
I thought I would try creating a mixin class using message forwarding.
I have a CancellableTask mix-in class which has some ivars and
implementation, and thus can't be implemented as a protocol.
Reading the intro to ObjC, it explains how to mimic multi-inheritance
using message forwarding.
If you have B inheriting from A, and you want to mix-in C, you simply
implement the method "forwardInvocation:" in B, which is called
whenever B receives a message it doesn't recognize, and forward any
messages meant for C to an instance C in B. I think you get my drift.
The problem I have with this is a practical one. Should I include the
method declarations of the mix-in class C, in B? B doesn't technically
implement them, and I will get compiler warnings if I do this. Yet the
reason for including a mix-in class in the first place is that in
practise B does respond to the methods of C.
Has anyone made use of this trick, and if so, how have they defined
the interface in the header files?
If you define these methods in a category of B (in the same header file
if you'd like to), the compiler will not complain for a missing
implementation.
Marco Scheurer
Sen:te, Lausanne, Switzerland
http://www.sente.ch
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.