Re: Convenience Methods
Re: Convenience Methods
- Subject: Re: Convenience Methods
- From: Uli Kusterer <email@hidden>
- Date: Thu, 27 Sep 2007 10:18:25 +0200
Am 27.09.2007 um 04:35 schrieb Jeff Laing:
Which would imply that "if the method says it returns
basic_plugin*, then thats all it returns".
Clumsy, not quite what you'd like, but 100% explicit and predictable.
Both C++ and Objective C never enforce this contract. An
NSMutableArray is a subclass of an NSArray. So, every place that
declares it returns an NSArray may return any of its subclasses.
Already, you can't be sure that "that's all it returns".
As I learned in the course of this thread, choosing "id" simply
shuts up some warnings, and since it's a Cocoa convention that
factory methods return an object of their class, or a subclass
thereof, you can be reasonably sure that that's what you get even
though it only says "id". Since Objective C doesn't support
overriding methods by type, it's the best we can do in this language.
Specifying a more specific type could cause the type mismatch
warnings to become unusable, because you'd get hundreds of them.
It ain't pretty, but unless ObjC gains type-based overriding like C+
+, I don't see another solution offhand.
Cheers,
-- M. Uli Kusterer
http://www.zathras.de
_______________________________________________
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