Re: resetting ivars safely
Re: resetting ivars safely
- Subject: Re: resetting ivars safely
- From: Uli Kusterer <email@hidden>
- Date: Thu, 13 Sep 2007 11:02:45 +0200
On 13.09.2007, at 03:12, Daniel Child wrote:
It makes sense for it to be a singleton. It will eventually be
interfacing with a component. And there is no need for "lots of
them." The same "machine" processes streams of words one set at a
time. No need to create a new machine for each set of data. I am
simply clearing fields that store input or that store output
temporarily.
Don't confuse objects in an OOP language with real-world, physical
objects: An object in OOP is simply a combination of data (=state)
and actions that modify this data. Hence, if you find you need to
replace 90% of the data, you might as well tear down and recreate the
object. That way, you don't duplicate clean-up code and risk it going
out of sync, and even if you have a -cleanUp method that's called
both by -reset and -dealloc, it's still two separate code paths that
may diverge by accident.
If you have some hardware you're interfacing to, it may help to
have separate objects for state and actual hardware control. All
state objects would share the same hardware controller, but would
nonetheless be separate. However, one can also over-engineer things,
and you didn't give enough information to say for certain in your
case. *In general*, you don't have objects that can be reset in OOP,
and instead you create new objects (the performance implications are
minimal, and if you find your case is different, *after profiling*,
then you can always refactor the design).
Cheers,
-- M. Uli Kusterer
http://www.zathras.de
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden