does python support mvc architecture
Thomas Heller
theller at python.net
Thu Feb 12 10:38:58 EST 2004
"John Roth" <newsgroups at jhrothjr.com> writes:
> <ketulp_baroda at yahoo.com> wrote in message
> news:f046efac.0402120627.948b7ed at posting.google.com...
>> Hi
>> Does python support MVC architecture? Java has register & notify
>> obsever methods in javax.util . Does python has these functions. If
>> not then how to register the views with the models & how to notify the
>> views that the model has been updated??
>
> I don't know of a notifier class in the standard library,
> but it's not all that difficult to write one. This is the
> one I am currently using:
>
> -----------------------------------------------------
> # module Notify
>
> class Notify(object):
> def __init__(self):
> self.listenerList = []
>
> def sendMessage(self, event):
> for callback in self.listenerList:
> callback(event)
> return
>
> def addListener(self, callback):
> self.listenerList.append(callback)
>
> def removeListener(self, callback):
> self.listenerList.remove(callback)
> -----------------------------------------------------
>
> callback has to be a callable of some kind,
> a bound method is perfectly acceptable and
> that's what I use. Works great.
I can heartily recommend the dispatcher module from Patrick O'Brian.
I'm still using a hacked up version from ActiveState's Python cookbook,
but there's also a newer version on sourceforge.
Thomas
More information about the Python-list
mailing list