Re: Creating a class cluster
Re: Creating a class cluster
- Subject: Re: Creating a class cluster
- From: Ondra Cada <email@hidden>
- Date: Mon, 29 Jul 2002 02:55:32 +0200
On Monday, July 29, 2002, at 02:04 , David Newberry wrote:
Thanks to all who responded to my question. I've got it pretty much
working, but still am experiencing some oddness... maybe. Just for ease I
took all the code out of my superclass and lived with the "incomplete
implementation" warnings.
Fair enough.
OTOH, in general case, you might have a small number of primitive methods
(which you can implement just to get rid of warnings), and a vast number
of conveniency methods (implemented using the primitive ones), which of
course would be in the "abstract" class implementation (to be inherited by
all the concrete subclasses). Like
@implementation Abstract
-(void)setValue:(int)n {
[self doesNotRecognizeSelector:_cmd];
}
-(void)zero { [self setValue:0]; }
-(void)random { [self setValue:random()]; }
-(void)setNumber:(NSNumber*)n { [self setValue:[n intValue]]; }
...
However, I have to put code like this inthe superclass:
- (MyClass *)initWithInfo:(id)data {
return [[MySubClass1 alloc] initWithInfo:data];
}
- (MyClass *)initWithPath:(NSString *)data {
return [[MySubClass2 alloc] initWithPath:data];
}
If I don't have this code which forwards the messages to the subclasses,
I get errors when sending an init... message to my superclass (eh
'[[MyClass alloc] initWithPath@"/"]'. Is this appropriate? It seems
alternatively that people have said "yes" and "no"... but chances are I
just misunderstood something. Also, from what Ondra said, do I take it
that (if this code is proper), those methods should each start with
"[self autorelease];"?
Or release.
It's actually quite simple: [MyClass alloc] always makes an instance of
MyClass (unless you reimplemented +alloc, and that's something I *really*
discommend). If you don't release it (before creating and returning a
different instance), it would leak.
---
Ondra Hada
OCSoftware: email@hidden
http://www.ocs.cz
private email@hidden
http://www.ocs.cz/oc
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.