Re: What classes have -init?
Re: What classes have -init?
- Subject: Re: What classes have -init?
- From: Greg Parker <email@hidden>
- Date: Thu, 11 Feb 2010 11:55:25 -0800
On Feb 11, 2010, at 9:03 AM, Gordon Apple wrote:
> It's unfortunate that all initializers don't at least call "init"
> internally. That would make subclassing easier if all one needs is to set a
> few ivars. In the earlier days of MacApp (Pascal and first C++ versions)
> there was a basic initializer, similar to "init", called by all classes,
> just for that purpose. Of course, Objective C at least sets them all to
> zero, reducing the need -- but it still would have been useful, sometimes
> eliminating the need to override multiple initializers.
The designated initializer pattern solves the problem in a similar way. Every initializer in a class is expected to call through that class's designated initializer eventually. When you subclass a class, you can override just the designated initializer to do your work and then call super's designated initializer. All of the superclass's other initializers will funnel through your code without any additional overrides.
--
Greg Parker email@hidden Runtime Wrangler
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please 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