On 18.09.2009, at 13:10, Jon Hull wrote:
I am writing a framework which runs on both Snow Leopard and the iPhone (i.e. it is entirely foundation stuff).

I always write my init and dealloc methods using the setter functions, but I am wondering what the proper convention is for immutable classes? Should I write a private setter method, or is it ok to just set the variable in init and release it in -dealloc. Thus:

(...) Is ether one better for a particular reason, or are they both ok, and it is just a matter of style? I am thinking that the second is probably better, because even a 'private' method could get called from outside of the class, and I couldn't guarantee it's immutability anymore. That is so different from what I normally do (I was taught to always use setter methods) that I wanted to check with the list first...

See here for a rationale on why it could be a bad idea to use accessors in init methods (and maybe even destructors):

http://zathras.de/blog-defensive-coding-in-objective-c.htm

And since immutable objects are not intended to be mutated at all, there should be only two places where ivars are changed: init and dealloc, so I don't think there's any need for mutators (accessors, for reading, are likely needed anyway).

Cheers,
-- Uli Kusterer
"The witnesses of TeachText are everywhere..."



_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to