Design Paterns: +/- Initializers and Subclassing
Design Paterns: +/- Initializers and Subclassing
- Subject: Design Paterns: +/- Initializers and Subclassing
- From: Christopher J Kemsley <email@hidden>
- Date: Sun, 2 Aug 2009 22:17:06 -0700
Ok, so here's the deal:
I have a class (CYMethod) that provides a standard interface for
multiple implementations of the same type (multiple ways in which to
read a file, for instance). Here are its constructors:
+ (CYMethod*) method {
return [ [ [CYMethod alloc] init ] autorelease ] ;
}
- (CYMethod*) init {
if ( self = [super init] )
{
}
return self ;
}
What I want to be able to do is subclass this, but only override the -
init method. However, if I use the above code and call
[CYMethodSubclass method]
I'll get back a new instance of CYMethod, not CYMethodSubclass.
How do I make the +method call return an initialized object of
whatever type the +method was sent to? (so that [CYMethodSubclass
method] returns [ [ [CYMethodSubclass alloc] init ] autorelease])
Thanks,
-Christopher
_______________________________________________
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