Re: inheritance and initialisation
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.