• 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
Re: super constructor encapsulation
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

References: 
 >super constructor encapsulation (From: "Ahmet Taha Sakar" <email@hidden>)

  • Prev by Date: Re: super constructor encapsulation
  • Next by Date: Possible to draw an NSMutableAttributedString into a CGContextRef?
  • Previous by thread: Re: super constructor encapsulation
  • Next by thread: Possible to draw an NSMutableAttributedString into a CGContextRef?
  • Index(es):
    • Date
    • Thread