• 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: 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


  • Follow-Ups:
    • Re: super constructor encapsulation
      • From: Scott Ribe <email@hidden>
    • Re: super constructor encapsulation
      • From: "Michael Novak" <email@hidden>
References: 
 >super constructor encapsulation (From: "Ahmet Taha Sakar" <email@hidden>)

  • Prev by Date: Re: super constructor encapsulation
  • Next by Date: Re: super constructor encapsulation
  • Previous by thread: Re: super constructor encapsulation
  • Next by thread: Re: super constructor encapsulation
  • Index(es):
    • Date
    • Thread