Re: Memory management question
Re: Memory management question
- Subject: Re: Memory management question
- From: Alastair Houghton <email@hidden>
- Date: Sat, 27 Mar 2004 23:43:15 +0000
On 27 Mar 2004, at 18:00, Jerry Krinock wrote:
>
I don't understand the recommendation to use the getter method [snip]
>
and the advice to always use the getter method [snip] instead of just
>
a direct reference [snip] when using foo in other methods in the
>
class.
>
>
What's the effective difference between these two expressions? All I
>
can
>
see is that the getter has the overhead of a message, while the direct
>
reference does not and should run faster.
The difference is that with the method in place, you can easily change
the implementation of your class (for instance, you may decide that
it's better to compute a value on the fly rather than keeping a copy in
each object). If you don't use the getter method, you may have to
change a lot more code.
The getter method also allows you to do other things, like log changes
to a property, which is pretty much impossible without using a
getter/setter approach.
I have to say that I do vary my implementations; for simple classes
whose implementation is unlikely to change and that are unlikely to be
subclassed, I often write direct references. For more complex classes,
or classes that might be subclassed, using the method approach is
certainly better.
Kind regards,
Alastair.
--
http://www.alastairs-place.net
[demime 0.98b removed an attachment of type application/pkcs7-signature which had a name of smime.p7s]
_______________________________________________
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.