Re: super constructor encapsulation
Re: super constructor encapsulation
- Subject: Re: super constructor encapsulation
- From: James Bucanek <email@hidden>
- Date: Fri, 13 Apr 2007 10:20:52 -0700
Ahmet Taha Sakar wrote on Friday, April 13, 2007:
>I create the instance with
>ClassA foo = [[ClassB alloc] initWithHeight:10 width:20 depth:30];
>
>I have seen that
>ClassA foo = [[ClassB alloc] initWithHeight:10 width:20];
>also works, which is the constructor for ClassA, but I dont want to allow
>this. I want to make it so that if one wants to initiate ClassB they have
>to use it's own constructor with depth parameter.
During development, I make sure that I don't call an inherited constructor (whoops, "initializer") by overriding it the subclass:
@interface ClassB
// The initializer ClassB should be using
- (id)initWithHeight:(int)h width:(int)w depth:(int)d
{
self = [super initWithHeight:h width:w];
... normal stuff
}
// Block inherited initializer
- (id)initWithHeight:(int)h width:(int)w
{
NSAssert1(false,@"Invalid constructor %s",__func__);
}
--
James Bucanek
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden