Re: Lack of Initializers or Factory Methods
Re: Lack of Initializers or Factory Methods
- Subject: Re: Lack of Initializers or Factory Methods
- From: Gordon Apple <email@hidden>
- Date: Mon, 03 Nov 2008 10:30:57 -0600
- Thread-topic: Lack of Initializers or Factory Methods
Is "self" even defined for a class object? If so, should case 1 (or
similar) be the assumed implementation for all of Cocoa? If not, then,
IMHO, the docs in general should specify which is is for each factory
method.
On 11/3/08 10:06 AM, "email@hidden"
<email@hidden> wrote:
> On Nov 3, 2008, at 10:53 AM, Gordon Apple wrote:
>
>> The following example is one of several I have run into recently.
>>
>> Inheritance is as follows: CAKeyframeAnimation:
>> CAPropertyAnimation :
>> CAAnimation. CAKeyframeAnimation has no explicit initializer or
>> factory
>> method. Dudney's book uses [CAKeyframeAnimation animation] to
>> create an
>> object. However, CAKeyframeAnimation has no such factory method.
>> CAAnimation does. Why should I assume that the "animation" factory
>> method
>> will return an object of class CAKeyframeAnimation instead of
>> CAAnimation
>> when it is not re-defined in CAKeyframeAnimation.h?
>>
>> The docs say that CAKeyframeAnimation shoud be created with the
>> inherited (from CAPropertyAnimation) animationWithKeyPath factory
>> method.
>> That raises the same issue.
>>
>> Is there a basic assumption that such factory methods are
>> implicitly
>> redefined for all subclasses?
>
> In Objective-C, classes are objects with inheritance. What you'll get
> back from a class convenience method is going to depend on how its
> implemented (and not necessarily whether it is redefined by a subclass.)
>
> Consider
>
> @interface Person : NSObject
> + (id)person
> @end
>
> @interface Child : Base
> @end
>
> Case #1
>
> @implementation Person
> + (id)person
> {
> return [[[self alloc] init] autorelease];
> }
> @end
>
> Case #2
>
> @implementation Person
> + (id)person
> {
> return [[[Person alloc] init] autorelease];
> }
> @end
>
> In case #1, [Child person] will return a Child instance to us.
> In case #2, [Child person] will return a Person instance to us.
>
> I think the CoreAnimation authors intended for case #1, but that's not
> what the documentation says.
>
> Creates and returns a new CAAnimation instance.
> + (id)animation
>
> Return Value
> An CAAnimation object whose input values are initialized.
>
> I'd recommend filing a bug against the documentation for clarification/
> correction.
>
> Jim
G. Apple
_______________________________________________
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