|
|||
|
Model, View, Controller question
I'm experimenting with a MVC pattern. It's new to me, but I'm getting on
fine with it. A question: Is it OK to have part of the model data inside the view widgets? The answer, at first glance, seems like "no", but here's the position: I have a bunch of text widgets which the user fills in, then they hit a button which says "do it". The view sends the "do it" signal to the controller, which relays it to the model. At this point the model needs the text in those widgets to start work. The options seem to be: 1) Have the view and controller update the model each time the text widgets are altered. The model keeps an up to date representation of what's in the text widgets. This is slow and duplicates data. 2) Have the controller query the view for the contents of the widgets when it gets the "do it" signal. It can then pass the complete information to the model. 3) Have the model query the view for the text when it needs it. "2)" seems the obvious way to go, but that communication doesn't fit any MVC diagrams I've ever seen to date. The question goes a little deeper than just text widgets. For example, I have a listbox containing a list of filenames which can be added to, deleted from, and reordered using buttons on the GUI. At the moment I have the list of filenames stored in the model as well as in the listbox widget. When the buttons are clicked, signals are passed around to the model which updates it's structure, then signals the view to update. That seemed the correct way at the time, but it means duplication of data and hence possible inconsistency. Perhaps the view should look after the list and only pass the contents into the model when the model actually needs it? What's guidelines are there for this issue? |
| Sponsored Links |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
|
|