• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Forwarding to mimic multiple inheritance
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

References: 
 >Forwarding to mimic multiple inheritance (From: Drew McCormack <email@hidden>)

  • Prev by Date: Re: Newbie Question (alloc, init, retain?)
  • Next by Date: Re: Trapping the close click?
  • Previous by thread: Forwarding to mimic multiple inheritance
  • Next by thread: Re: Forwarding to mimic multiple inheritance
  • Index(es):
    • Date
    • Thread