super constructor encapsulation
super constructor encapsulation
- Subject: super constructor encapsulation
- From: "Ahmet Taha Sakar" <email@hidden>
- Date: Fri, 13 Apr 2007 09:13:10 -0700
Hello,
I have created two classes. Here is something like a summary. I'm writing
it like c++ since it's shorter.
ClassA
{
int height;
int width;
ClassA(int h, int w) { height = h; width = w;}
}
ClassB : ClassA
{
int depth;
ClassB(int h, int w, int d) { super(h, w); depth = d}
}
if you can, think of this with objective-c and something like:
- (id) initWithHeight: (int)h width: (int)w depth: (int)d
{
if (self = [super initWithHeight:h width:w])
{
depth = d;
}
return self;
}
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.
_______________________________________________
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