Re: abstract class
Re: abstract class
- Subject: Re: abstract class
- From: Shawn Erickson <email@hidden>
- Date: Thu, 24 May 2007 22:43:28 -0700
On May 24, 2007, at 8:12 PM, Daniel Child wrote:
Thanks Shawn and Bill.
For clarification, will the selection of which factory subclass is
called be based on a parameter passed to the interface in the
abstract class? I was thinking in terms of calling a public class
interface, something like:
@implementation abstractClass
{
NSString * type
}
+ (id) newThing: (NSString *) type;
But then how does this get implemented at both top ("pseudo-
abstract") and lower ("concrete") levels.
Here, I'm not even trying to initialize a value, but rather choose
between creating a ConcreteA or ConcreteB.
@implementation abstractClass
+ (id) newThing: (NSString *) type;
{
if ([type isEqualToString: @"A"])
???
else if ([type isEqualToString: @"B"])
???
}
It is the lower concrete classes that I think should set the
inherited type variable to "A" or "B" (not that such a variable is
necessary). But this whole thing if initing the super class is
confusing me because the examples were for instance init examples
and I'm trying to create a class method.
Still confused....
@interface AbstractClass {
....
}
+ (id) newThing:(NSString*)type
.... base interface ....
@end
@implementation AbstractClass
+ (id) newThing:(NSString*)type
{
if ([type isEqualToString:@"A"]) {
return [[[ClassForTypeA alloc] init] autorelease];
} else if ([type isEqualToString:@"B") {
return [[[ClassForTypeB alloc] init] autorelease];
} ...etc...
}
@end
@interface ClassForTypeA : AbstractClass {
....
}
....
@end
@interface ClassForTypeB : AbstractClass {
....
}
....
@end
-Shawn
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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