On Wed, Jun 11, 2008 at 12:01 AM, John Engelhart
<[EMAIL PROTECTED]> wrote:
>
> On Jun 10, 2008, at 11:28 AM, Charles Srstka wrote:
>>
>> I think the problem is that if NSArray has +[NSArray array] returning an
>> NSArray, then NSMutableArray has to return an NSArray also, since it can't
>> have a different method signature for the same method. As a result, if you
>> called +[NSMutableArray array], the compiler would think you were getting a
>> regular, non-mutable NSArray, and you'd get a warning if you tried to do
>> this, although the code would still work:
>
> No, each class is allowed to define different types for the same method:
>
> http://developer.apple.com/documentation/Cocoa/Conceptual/ObjectiveC/Articles/chapter_9_section_2.html#//apple_ref/doc/uid/TP30001163-CH16-TPXREF161
>
> This whole business about '(NSArray *) means NSArray AND any of it's
> subclasses' is the result of sloppy thinking and confusing 'able to' with
> 'as per spec'.
>
> If you declare a method prototype as '-(NSArray *)resultsArray', then you
> have explicitly communicated that a NSArray is going to be returned.  Not a
> NSMutableArray. Not 'Jimmies groovy array with red pin stripes'.

This is simply not true. Returning (NSArray*) only means "I will
return an object that you can assume is an NSArray". Not a single one
of the convenience methods on NSArray actually return an NSArray, they
all return one subclass or another.

>A NSArray. Period.  A NSMutableArray != a NSArray.

No, All NSMutableArrays are also NSArrays, that is the very definition
of subclassing. In any object-oriented system, subclassing establishes
an "is-a" relationship between classes.


> If you're going to be returning (or accepting) more than a single class, you 
> use id, which clearly communicates your intentions.

Again, no. It is perfectly acceptable to pass an NSMutableArray where
an NSArray is expected.

-- 
Clark S. Cox III
[EMAIL PROTECTED]
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to