Design Element
Comment on "A Quick Objective-C 2.0 Tutorial"
by Matt Patenaude — Jun 02
I'd just like to point out one unrelated point about the +movie convenience method.

While that is the most common form of such a convenience method, I've found that this is generally safer and more powerful:

+ (id)movie { return [[[self alloc] init] autorelease]; }

The benefit of using self to do the initialization is that the +movie method does not have to be reimplemented should Movie be subclassed-- it will continue to return the correct object, ie, it will return a Movie instance when called on the Movie class, and a HorrorMovie instance when called on the HorrorMovie class, without modification.
Back to "A Quick Objective-C 2.0 Tutorial"
Design Element

Copyright © Scott Stevenson 2004-2015