Using MVC when the model is dynamic

Brian Kelley bkelley at wi.mit.edu
Thu Oct 2 09:34:59 EDT 2003


Cameron Laird wrote:

> In article <YkPeb.10891$RW4.8963 at newsread4.news.pas.earthlink.net>,
> Mitch Chapman  <mitchchapman at earthlink.net> wrote:
> 
>>I'm confused by the comments about the model needing to poll for new
>>instructions from the view.  (BTW does this mean you usually prefer to
>>combine view and controller responsibilities in a single entity, rather
>>than implement them separately?)
> 

Maybe when I say polling it is a symantic issue, but in your run method:

     def run(self):
         """Run the model in its own thread."""
         self._stopped = 0
         i = 0.0
         di = math.pi / 8.0
         while not self._stopped:
             self._state.value = math.sin(i)
             i += di

isn't "while not self._stopped" a method of polling?  This variable is 
still set asynchronously.  This is the only point that I was getting at, 
for example if you had many states in your model that can be altered, 
you still need to periodically check to affect these state changes.

 >>If that's the case, can you define a model-controller class which
 >>receives view events and translates them into method invocations on
 >>an associated model?  That does seem like a lot of work, but it
 >>would let the model remain ignorant of -- loosely coupled to --
 >>its observers.

Yes.  This is actually what I do.  I still consider this in the realm of 
polling though (note that I am talking about receiving the model change 
event and converting it to a method invocation here).  Using the normal 
threading model the polling is hidden as in your example, i.e. keep 
checking to see if self._stopped is true.

Perhaps polling is not the proper way to talk about this.  But, tt helps 
my mental picture of what is going on though in that "at any time there 
could be a state change so if you are interested in it, keep checking 
for the change."  This mental picture works (for me at least) when 
running the model in a thread or running the model in another process.

Brian.





More information about the Python-list mailing list