• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Convenience Methods
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >RE: Convenience Methods (From: Jeff Laing <email@hidden>)

  • Prev by Date: Re: Convenience Methods
  • Next by Date: Re: Core data - getting fresh records
  • Previous by thread: Re: Convenience Methods
  • Next by thread: RE: Convenience Methods
  • Index(es):
    • Date
    • Thread