Re: Accessor methods and (auto)release: conclusion
Re: Accessor methods and (auto)release: conclusion
- Subject: Re: Accessor methods and (auto)release: conclusion
- From: Shawn Erickson <email@hidden>
- Date: Tue, 6 Aug 2002 08:38:36 -0700
On Tuesday, August 6, 2002, at 07:35 AM, Ondra Cada wrote:
What we need is find which of all the possible ways is the "right",
or, rather, *standard* one. This standard way needs not to be
documented; any other one *SHOULD* be documented.
Yup!
It seems now that the standard way for Cocoa is this:
-getter { return [[ivar retain] autorelease]; }
-(void)setter:o { if (ivar==o) return; [ivar release]; ivar=[o
retain]; }
-(void)dealloc { ... [self setter:nil]; ... }
or, naturally, anything *functionally equivalent* -- in other words,
fulfilling the agreement "the vended object would be valid (at least)
in the entire scope of the autorelease pool (current in the moment the
getter vas used)". Those plain accessors you advocate alas are not!
Exactly! It follows the expected behavior seen when using [NSString
string] or [NSMutableString stringWithCapacity:] (as so on...). I
classify them the same as Ondra does and I think it works better and
results in cleaner more consistent looking code.
You don't have to like it, and you don't have to use it either;
neverhteless, if you are writing a class which DOES NOT fulfil this
agreement -- and, if there is the remotest possibility the class would
be used by any 3rd party, of course -- you should document it. That's
all.
Again true... you don't need to use it (in some case it is overkill and
can be a performance issue) but if others may use your class and it
doesn't follow the expected pattern then PLEASE document that it does
NOT do so.
-Shawn
_______________________________________________
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.