Re: Weird Apple Sample code
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