Re: Class clusters - infinite loop?
Re: Class clusters - infinite loop?
- Subject: Re: Class clusters - infinite loop?
- From: Tim Lucas <email@hidden>
- Date: Mon, 27 Jun 2005 13:32:51 +1000
On 26/06/2005, at 11:19 AM, Wade Tregaskis wrote:
Perhaps a specific example would help. Most class clusters never
return self from their init methods - they allocate a new instance of
whichever specific hidden subclass they're going to use, and release
self. How then are you supposed to call [super init] (or equivalent)
in your subclass? You can't. Which means you probably can't rely on
any of the superclass behaviour.
Wah? He was talking about the init in the class cluster's common
superclass, in which it is probably a good idea to call super init:
- (id)initWithData:(NSData *)someData {
self = [super init];
[self release];
// look at the data
if([someData length] > 100) {
self = [[BigDataHolder alloc] initWithData:someData];
}
else {
self = [[SmallDataHolder alloc] initWithData:someData];
}
return self;
}
To reiterate my earlier example with NSOutputStream, what I wanted to
do was create a subclass of it which performs a cryptographic
operation on the data as it goes out - a SHA1 hash, for example. Now,
it seems NSOutputStream is a cluster with at least 3 private
subclasses for each of it's three modes of operation. I don't want to
subclass three private classes, or extend them with categories. The
may change in future. Also, I don't need the redundancy. All I want
is the documented public behaviour of NSOutputStream.
Doesn't SHA1 need the entire dataset? Streams need to support
incremental reads and writes.
This doesn't sound like it should be a subclass of NSOutputStream
anyway, it should more like a pipe. You may want your SHA1'd data to go
to memory, a buffer or a file, or any other NSOutputStream subclass.
- tim lucas
_______________________________________________
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