• 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
@protocol for abstract base class
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

@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.


  • Prev by Date: (Newbie) Prototypes don't seem to compile?
  • Next by Date: [Solved]- Re: NSArrayController and bindings
  • Previous by thread: Re: (Newbie) Prototypes don't seem to compile?
  • Next by thread: question about NSNaturalTextAlignment
  • Index(es):
    • Date
    • Thread