Re: Multiple inheritance and objective-c
Re: Multiple inheritance and objective-c
- Subject: Re: Multiple inheritance and objective-c
- From: BlueHorseshoe <email@hidden>
- Date: Mon, 21 Mar 2005 23:20:23 -0500
- Resent-date: Mon, 21 Mar 2005 23:28:49 -0500
- Resent-from: BlueHorseshoe <email@hidden>
- Resent-message-id: <email@hidden>
- Resent-to: email@hidden
A real multiple inheritance solution was described last September and discussed in a cocoa-dev thread titled "Multiple Inheritence (Was: Is _objc_flush_caches_(Class) necessary to swizzle methods?)":
http://www.cocoabuilder.com/archive/message/2004/9/25/118263
http://www.cocoabuilder.com/archive/message/cocoa/2004/9/26/118320
You can achieve a kind of "weak" multiple inheritance in Obj-C by using the #include or #define directives of the C-preprocessor. Omni does the later in their frameworks to effectively place all the code used in multiple, otherwise unrelated, classes in one place. LIkewise, one can then implement what are effective "concrete" protocols this way as well.
The technique is simple and work well in Xcode. The only problem, which is minor, is that if you place a breakpoint in the shared code in registered for only one of the classes that use that code.
So, here is what you do to use #include:
1.) Write you shared code out in file that is not added to your target so it is not complied, as will not compile independently. The shared should be method implementations only, that is outside of the normal @implementation - @end blocks.
2.) Use #include like so:
@implementation MyClassWithWeakMultipleInheritence
#include "myCommonMethodImpementations.m"
- (void)myClassSpecificMethod
{
NSLog(@"This is myClassSpecificMethod ofÂ
MyClassWithWeakMultipleInheritence");
}
@end
If you have only short amount of code that is common to multiple classes you can use a multiple line #define instead of an entire file.
Hope this helps, I know it did for me.
Gordon G.
_______________________________________________
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