GUI/data object oriented design question
cliechti at gmx.net
Wed Nov 28 01:59:27 CET 2001
[posted and mailed]
george young <gry at ll.mit.edu> wrote in
news:20011127180304.6aa502e6.gry at ll.mit.edu:
> I think this may work, but the explicit manipulation of "data_type"
> etc. seems pretty kludgy. Is there some "pattern" that solves this?
> My first thought was for each GUI object to have a reference to it's
> respective data object, e.g. a StepWin has a Step reference. But then
> the Run has to maintain it's own parallel list of Steps, while the
> RunWin has it's list of StepWins. And the resulting references needed
> by callbacks get very ugly.
thats called "Model-View-Controller" (MVC). your GUI component (View) has
to get its value from the Model. a Controller e.g. a button changes the
state of the Model.
the "callback" is solved by the "observer pattern". e.g you implement a
"update(source, args)" method in you GUI components and register it at the
Model. the Model is then responsible to call all "update"s when it changes.
such an oberservable class (register, remove, call observers) can be
programmed very generally and you just inherint from that class when a
Model needs it (very easy as python as multiple inheritance)
here's an implemenation example:
> I've been staring at this stuff far too long and would be very grateful
> for some suggestions. I hope I've explained the problem enough...
hope i've undertand you question correctly...
Chris <cliechti at gmx.net>
More information about the Python-list