Re: super constructor encapsulation
Re: super constructor encapsulation
- Subject: Re: super constructor encapsulation
- From: Jim Correia <email@hidden>
- Date: Fri, 13 Apr 2007 12:37:36 -0400
On Apr 13, 2007, at 12:13 PM, Ahmet Taha Sakar wrote:
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.
In Objective-C, they are called initializers, not constructors.
Objective-C is dynamically dispatched; you can't enforce this at
compile time.
What you can do is
- document that -initWithHeight:width:depth: is the designated
initializer and should/must be used
- override -initWithHeight:width: to assign some reasonable default
to depth, or
- override -initWithHeight:width: to raise an exception saying that
the designated initializer must be used
Jim
_______________________________________________
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