Re: substring return a new string?
Re: substring return a new string?
- Subject: Re: substring return a new string?
- From: Marco Scheurer <email@hidden>
- Date: Thu, 18 Mar 2004 21:11:40 +0100
On Mar 18, 2004, at 6:45 PM, Shawn Erickson wrote:
On Mar 18, 2004, at 9:12 AM, Ondra Cada wrote:
On Thursday, Mar 18, 2004, at 17:32 Europe/Prague, Marco Scheurer
wrote:
so far as I can say the only remaining possibility is to *declare*
the method returning mutable data, and *document* the fact it is
always freshly-created: let then the client decide what to do with
>> it:
@interface ...
...
-(NSMutableArray*)someArray; // created each time the message is
sent, not stored then
...
// implementation exactly as you suggested.
Certainly not! Declaring the method as returning NSMutableArray
documents the fact that the user can modify the returned array. This
is most likely not what you want.
Why not, in this case? Nobody can ever share the array with the user
(who may change it), unless the user (who may change it) allows it
himself, so I would say all right. Am I overlooking something
important?
Yeah as long as the implementation does something like what was
outlined in your email it is safe. Of course you are forcing your
implementation to be done in a more specific way as a result of
interface definition. Less freedom in implementation may or may not be
an issue depending on the target "market" so to speak of your class.
It may be safe, but it does not make it right. What you do is
advertising a mutable property of your object, and the user could
legitimally think that he can modify this property. I've never seen a
class returning a mutable property with the idea "here, take this and
change it as you want, I don't care". This would be extremely bad
design IMHO (and anyway, returning mutable things, even ivars of your
object, is bad in general).
Marco Scheurer
Sen:te, Lausanne, Switzerland
http://www.sente.ch
_______________________________________________
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.