views:

62

answers:

1

Im working on optimizing my design in terms of mvc, intent on simplifying the api of the view which is quite nested even though Iv built composite widgets(with there own events and/ pubsub messages) in an attempt to simpify things.

For example I have a main top level gui class a wxFrame which has a number of widgets including a notebook, the notebook contains a number of tabs some of which are notebooks that contain composite widgets. So to call the methods of one of these composite widgets from the controller I would have

 self.gui.nb.sub_nb.composite_widget.method()

To create a suitable abstraction for the view I have created references to these widgets (whose methods need to be called in the controller) in the view like so

 self.composite_widget = self.nb.sub_nb.composite_widget()

so that in the controller the call is now simplified to

 self.gui.composite_widget.method()

Is this an acceptable way to create an abstraction layer for the gui?

+1  A: 

Well that's definitely one way to handle the issue. I tend to use pubsub to call methods the old fashioned way though. Some people like pyDispatcher better than pubsub. The main problem with using multi-dot method calling is that it's hard to debug if you have to change a method name.

Mike Driscoll
What do you mean by using "pubsub to call methods the old fashioned way" do your mean that you call a method in your gui once your controller or what ever recieves a message from..? Most of the time methods that I have to call are setters for say setting the initial value of a widget based on a config.. if the value of a widget is changed by a user then I mostly use pubsub to broadcast that value, so I usually dont have to call getters.. although sometimes I do.
volting
Yeah, that's what I meant. One program I have checks for updates in my mailbox every couple of minutes. To update my program, I can call the method directly, or I can be lazy and use pubsub. I almost always use pubsub in this case to broadcast that I've received an email. The receiver in my main programs sees the message and acts on it by updating my UI and popping up a message box to let me know.I apologize for not being clearer.
Mike Driscoll
Thanks for clearing that up, no need to apologize though. Theres so many ways it could be implemented, so I just wanted to make sure I understood...
volting