Re: Class clusters - infinite loop?
Re: Class clusters - infinite loop?
- Subject: Re: Class clusters - infinite loop?
- From: Lee Morgan <email@hidden>
- Date: Sat, 25 Jun 2005 02:19:00 -0400
The easy way would be to add a initWithSmartData method to DataHolder
which does what your initWithData method currently does. And then
allow BigDataHolder and SmallDataHolder to call initWithData of
DataHolder.
- Lee
On Jun 25, 2005, at 2:08 AM, Steve Canfield wrote:
This is a repost from what I just posted to
comp.sys.mac.programmer.help, but I thought cross posting might be
helpful.
I'm trying to create a class cluster.
First is my super class -- this is the init method
DataHolder.m
- (id)initWithData:(NSData *)someData {
// look at the data
if([someData length] > 100) {
self = [[BigDataHolder alloc] initWithData:someData];
}
else {
self = [[SmallDataHolder alloc] initWithData:someData];
}
return self;
}
IE we chose the subclass based on the data... seems simple enough
Now onto the subclass's init methods
BigDataHolder.m // basically same for SmallDataHolder
- (id)initWithData:(NSData *)someData {
if(self = [super initWithData:someData]) {
// do some initialization here, etc
}
return self;
}
Anyway, I think you can see the problem here. This is going to go
into an infinite loop. What's the solution? Should I skip the call
to super and just call super super's init? Should I class sniff in
my DataHolder init? Is there some simple way out of this?
Class clusters seem cool but the documentation on how to actually
implement them has been a little off so far.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden