@protocol for abstract base class
@protocol for abstract base class
- Subject: @protocol for abstract base class
- From: Troy Dawson <email@hidden>
- Date: Tue, 24 Feb 2004 18:18:54 -0800
believe or not the following C hack to get an ABC from a protocol
(without having to declare the implementation of the ABC) and C++
namespace for factory methods works.
-- except #1 --
declaring @interface UIElementPrivate : UIElement
doesn't work as expected, I must instead declare:
@interface UIElementPrivate : NSObject<UIElementMethods>
-- except #2 (probably related) -- when I try to subclass
UIElementPrivate here:
@interface UIBox : UIElementPrivate
I get an internal compiler error (it works fine (AFAIK...) if
UIElementPrivate is a leaf class).
I'm not too enamored of this style, but I want to be able to declare an
ABC without the hassle of declaring an @implementation of the base
class.
Is there a better way to accomplish this (Objective-C++ idioms OK) ?
code follows:
#######.h file:
@protocol UIElementMethods
@end
typedef NSObject<UIElementMethods> UIElement;
namespace UI
{
UIElement* createBox(const CGRect& frame);
}
#######.mm:
@interface UIElementPrivate : NSObject<UIElementMethods>
{
CGRect frame;
}
@end
@implementation UIElementPrivate
@end
@interface UIBox : UIElementPrivate
{
}
- (id) initWithFrame: (const CGRect&) frame
@end
@implementation UIBox
- (id) initWithFrame: (const CGRect&) frame
{
self = [super init];
self->frame = frame;
}
@end
UIElement* UI::(const CGRect& frame, FrameStyles frame_style)
{
return [[[UIBox alloc] initWithFrame: frame frameStyle: frame_style]
autorelease];
}
_______________________________________________
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.