Re: MVC question about updating the Model
Re: MVC question about updating the Model
- Subject: Re: MVC question about updating the Model
- From: Quincey Morris <email@hidden>
- Date: Fri, 16 Apr 2010 10:51:46 -0700
On Apr 16, 2010, at 06:30, Matt DeFoor wrote:
> This is where I'm having difficulty determining what should be
> standard practice. Would it be better to post a notification that
> indicates the resource should update itself? Or is it good enough to
> leave it as is?
>
> One other approach I've considered is whether the Model should have
> the ability to update itself at all. Should the controller be
> responsible for updating the resource always?
I think your original approach is just fine.
You've encapsulated the "how" of updating your data model in the data model itself, which seems correct, and you just had to decide the mechanism of "when".
For manual updates initiated from the UI, your data model must have a public "update" method that is called by the window controller from the relevant button's action method. (Or, say, from an equivalent menu item hooked up to the same action method.)
For timed updates, you seem to have a choice of putting the timer in your data model, or putting the timer in your window controller. One good way to decide this is to ask yourself this question:
If I were to have *two* windows and window controllers showing this information, would I want to have a separate timer in each controller?
With the limited information you've given us, the answers seems to be "no". You'd probably want both windows to show updated information on the same schedule. Therefore, the auto-update timer needs to be in the data model itself.
If, on the other hand, the requirements of your application would dictate separate timers per window, then the timers need to be in the window controllers.
_______________________________________________
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