Re: semantics of init
Re: semantics of init
- Subject: Re: semantics of init
- From: Hannes Friederich <email@hidden>
- Date: Thu, 05 Jun 2003 11:04:56 +0200
While I do perfectly understand the reasons to use accessors in -init, there
may be some very situations where this is inappropriate.
One case may be immutable objects. In that case, the variables will be set
in the designated initializer. So why make a big effort and write setters
when they will be used only once?
Another situation would be when the setting of a variable is connected with
some other action, as for example a notification being sent. Of course, one
can in that case write a public and a private setter with the private setter
setting the variable and the public setter calling the private setter and
posting the notification (This is more a design problem)
The third situation are objects where the internal state does not correspond
with the publicly provided accessors. Just imagine the black box scenario
provided in may oo-tutorials and books. I for example had written a class
which uses two NSMutableArrays to store some of the data and wrote an
interface for accessing the data within these two arrays. The arrays itself
never reach outside the object, so why should I write accessors when the two
variables only are set during init and accessed from withing the objects
functions? Such "opaque" objects, where the internal state does not exactly
correspond with the public interface are harder to maintain anyway. But as
long as the writer of the objects makes this one working perfectly seen from
the outside, everything is ok
Just my 2 cents
Hannes
_______________________________________________
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.