Re: Mutable classes and class clusters
Re: Mutable classes and class clusters
- Subject: Re: Mutable classes and class clusters
- From: Rob Rix <email@hidden>
- Date: Sat, 15 Sep 2001 16:59:44 -0400
The point is that it allows you to tell the user of a class that "I will
not modify this (argument) object", or "You may not modify this object"
and so forth.
Consider something like;
- (NSArray*)windows;
versus
- (NSMutableArray*)windows;
In the first, you're handed an array which you're not allowed to change.
In the second, the type is telling you that you can change it.
If you find yourself in a situation where you often make copies of an
object before returning it, or passing it as an argument, then a mutable/
immutable class is useful.
Okay, this would also solve another of my problems: the problem of locking
a spline so that it won't be modified.
Makes sense...
Essentially. Don't forget to collect any garbage in the init method,
though.
Such as removing the instance of the public class that was just allocated?
You may also want to handle serialization; otherwise you can become
locked in with a certain implementation. "replacementObjectForCoder:"
should be helpful, there.
Ah, yes. This will be useful once I finally get around to having
everything adopt the coding protocol :)
I can't see any good reasons for doing that.
Okay, excellent.
Thanks very much, John.
-- Rob
For this is summer--we spin slowly on the edge of song. - Kira Byers