• 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: Weird Apple Sample code
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Weird Apple Sample code


  • Subject: Re: Weird Apple Sample code
  • From: "Sherm Pendley" <email@hidden>
  • Date: Thu, 13 Dec 2007 09:26:24 -0500

On Dec 13, 2007 7:38 AM, Ruotger Skupin <email@hidden> wrote:


> Obviously not returning the class you ask for is evil IMHO


I realize that the code you asked about isn't actually doing this, but I
just wanted to add that returning a different class from -init is fairly
common and not at all evil. Class clusters do it all the time - when you
call [[NSMutableArray alloc] init], what you get back is *not* an instance
of NSMutableArray, it's an instance of a private subclass of NSArray.

The "normal" contract in OO programming is that, for a method that is
documented to return class Foo, what you'll get back may be an instance of
either Foo or a subclass of Foo. Because of polymorphism, your code doesn't
need to know or care which is the case.

sherm--
_______________________________________________

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: 
 >Weird Apple Sample code (From: Ruotger Skupin <email@hidden>)

  • Prev by Date: Re: Weird Apple Sample code
  • Next by Date: Need the Why and How of mouseDragged:
  • Previous by thread: Re: Weird Apple Sample code
  • Next by thread: NSViewControllerArray?
  • Index(es):
    • Date
    • Thread