Let's say we have a class Base.
@inerface Base : NSObject
{
}
+(id) instance;
@end
@implementation Base
+(id) instance
{
return [[[self alloc] init] autorelease];
}
-(id) init
{
...
}
@end
And we have a derived class Derived.
@interface Derived : Base
{
}
@end
Which reimplements the init method.
Now we want to create an instance of Derived class using class method +(id) instance.
id foo = [Derived instance];
And now foo is actually a Base class.
How to achieve foo to be a Derived class in this case?
Should I reimplement all the class method for derived classes ? (actually immplementation will be totally the same).
Is there a more elegant way ?