• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Mutable and Immutable Designs
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.


  • Follow-Ups:
    • Re: Mutable and Immutable Designs
      • From: Wade Tregaskis <email@hidden>
  • Prev by Date: Re: Is that really a bug at all? (was: Re: Ugly bug in Foundation, beware!)
  • Next by Date: Re: Representing UTC time in a readable format
  • Previous by thread: NSXMLParser crashes
  • Next by thread: Re: Mutable and Immutable Designs
  • Index(es):
    • Date
    • Thread