• 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: inheritance and initialisation
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: inheritance and initialisation


  • Subject: Re: inheritance and initialisation
  • From: James Dempsey <email@hidden>
  • Date: Thu, 14 Aug 2003 17:14:27 -0700

For a full explanation, see the section Memory Mangement in The Objective-C Programming Language book online (specifically the Allocating and Initializing Objects section, which talks about "Coordinating Classes" and "The Designated Initializer").

http://developer.apple.com/documentation/Cocoa/Conceptual/ObjectiveC/ 4objc_runtime_overview/index.html

(I started typing a general explanation, but realized that the docs do a better job than I could in a few paragraphs.)

In the NSBezierPath case you mention, since NSBezierPath does not seem to have any additional initializers other than init, then init would be the class' designated initializer.

If your subclass has some other initializer (initWithPoints: for example, which sets a bunch of control points for the path) you would want to make sure that your initializer calls [super init].

You also will want to 'cover' the superclass' init method, with your own init method that calls your more complex initializer. (In the initWithPoints: example, the subclass' version of init should call initWithPoints: with some default set of points. If you didn't 'cover' the superclass' version of init, you could instantiate an instance of your subclass, initialize it with init, but none of the point-related setup would occur, since it is the superclass' version of init being called.)

I hope that helps a bit - again, the documentation is much more explicit than one can be in a few paragraphs.

-James

---------------------------
James Dempsey
Operations Engineer
Apple Software Customer Seeding
Apple Software Engineering

email@hidden
On Thursday, August 14, 2003, at 3:14 PM, Richard Chamberlain wrote:

Hello,

I want to create a new sub class of NSBezierPath so I can store a number of extra attributes along with it's current set, a colour for instance.

Obviously I need to add a number of instance variables and supporting methods for these so what I want to know is how, or more specifically which initialisation method do I override?

This is more of a general question - for instance in a class that contains a number of initialisers how do I know which to use?

In the case of NSBezierPath according to its header file it doesn't re-implement init so I presume the class method bezierPath calls init so implementing that would work?

Many thanks for any help,

Richard
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: inheritance and initialisation
      • From: Richard Chamberlain <email@hidden>
References: 
 >inheritance and initialisation (From: Richard Chamberlain <email@hidden>)

  • Prev by Date: Re: help trying to locate sigsegv error please
  • Next by Date: Re: CFSocketCallBack
  • Previous by thread: inheritance and initialisation
  • Next by thread: Re: inheritance and initialisation
  • Index(es):
    • Date
    • Thread