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

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


  • Follow-Ups:
    • Re: super constructor encapsulation
      • From: James Bucanek <email@hidden>
    • Re: super constructor encapsulation
      • From: Jim Correia <email@hidden>
    • Re: super constructor encapsulation
      • From: Scott Ribe <email@hidden>
  • Prev by Date: Re: Sorting Array Alphabetically
  • Next by Date: Re: super constructor encapsulation
  • Previous by thread: Re: NSMutableArray becomes NSString?
  • Next by thread: Re: super constructor encapsulation
  • Index(es):
    • Date
    • Thread