Re: abstract class
Re: abstract class
- Subject: Re: abstract class
- From: Daniel Child <email@hidden>
- Date: Thu, 24 May 2007 23:12:59 -0400
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....
On May 24, 2007, at 12:12 PM, Bill Bumgarner wrote:
On May 24, 2007, at 8:44 AM, Daniel Child wrote:
I have just started studying this stuff and must be missing
something obvious, but even the gnu documentation mentions
abstract classes without giving an example. Could anyone show the
briefest example of how it works in Obj-C? Thanks in advance.
What Shawn said...
And, given:
@interface
PublicThatHappensToBeAbstraactButYourClientsDoNotKnowOrCare : NSObject
... API for your Abstract public interface here ...
+ (PublicThatHappensToBeAbstraactButYourClientsDoNotKnowOrCare *)
publicWithFoo: (Foo *) aFoo; // create a new Public from a Foo
@end
// private begins
@interface
SomeVeryConcreteSubclassThatIsTotallyOptimizedToDealWithFoos :
PublicThatHappensToBeAbstraactButYourClientsDoNotKnowOrCare
... declare whatever you need for this specific implementation ...
- initWithFoo: (Foo *) aFoo;
@end
@implementation
SomeVeryConcreteSubclassThatIsTotallyOptimizedToDealWithFoos
... your overrides of the abstract public interface that are highly
optimized for handling Foos here ...
- initWithFoo: (Foo *) aFoo;
{
... [super designatedInitializer] ...
... init with the Foo ...
return self;
}
@end
// private ends
@implementation Abstract
+ (PublicThatHappensToBeAbstraactButYourClientsDoNotKnowOrCare *)
publicWithFoo: (Foo *) aFoo; // create a new Public from a Foo
{
return
[[[SomeVeryConcreteSubclassThatIsTotallyOptimizedToDealWithFoos
alloc] initWithFoo: aFoo] autorelease];
}
@end
_______________________________________________
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