Mutable and Immutable Designs
Mutable and Immutable Designs
- Subject: Mutable and Immutable Designs
- From: Francisco Tolmasky <email@hidden>
- Date: Fri, 4 Jun 2004 14:55:02 -0700
I've been trying to make my classes mutable and immutable recently.
I've taken Apple's approach of just not supporting the mutable methods
in the immutable class, as so:
@interface myClass : NSObject
{
NSString *name;
}
- (NSString *)name;
@end
@interface myMutableClass : myClass
{
}
- (void)setName:(NSString *)aName
@end
This all works very well except when it comes to writing copyWithZone:
and mutabelCopyWithZOne:
For my immutable class i do this:
- (id)copyWithZone:(NSZone *)aZone
{
return [self retain];
}
- (id)mutableCopyWithZOne:(NSZone *)aZone
{
return [(MyMutableClass *)[MyMutableClass alloc] initWith: self];
}
This seems to work fine, but my question is whether im doing the right
thing when in my mutable class i redefine copyWithZOne: like this:
- (id)copyWithZone:(NSZone *)aZone
{
return [self mutableCopyWithZone: aZone];
}
It seems to make sense.
Also, What happens when i make a subclass? All my subclasses must
necessarily be mutable, since i cant subclass from my immutable one
then make a mutable version without redefining everything in my mutable
class it would seem.
Thanks for all the help!
Francisco Tolmasky
email@hidden
http://www-scf.usc.edu/~tolmasky/
_______________________________________________
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.