• 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
Forwarding to mimic multiple inheritance
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Forwarding to mimic multiple inheritance


  • Subject: Forwarding to mimic multiple inheritance
  • From: Drew McCormack <email@hidden>
  • Date: Wed, 28 May 2003 15:39:45 +0200

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?

Drew

========================================
Dr. Drew McCormack (Kmr. R153)
Afd. Theoretische Chemie
Faculteit Exacte Wetenschappen
Vrije Universiteit Amsterdam
De Boelelaan 1083
1081 HV Amsterdam
The Netherlands

Email email@hidden
Telephone +31 20 44 47623
Mobile +31 6 483 21307
Fax +31 20 44 47629
_______________________________________________
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.

  • Follow-Ups:
    • Re: Forwarding to mimic multiple inheritance
      • From: "John C. Randolph" <email@hidden>
    • Re: Forwarding to mimic multiple inheritance
      • From: Marco Scheurer <email@hidden>
  • Prev by Date: Trapping the close click?
  • Next by Date: Interface Builder and projects with variable number of windows
  • Previous by thread: Re: Trapping the close click?
  • Next by thread: Re: Forwarding to mimic multiple inheritance
  • Index(es):
    • Date
    • Thread