[Tutor] design question

Alan Gauld alan.gauld at btinternet.com
Sun Sep 12 22:02:21 CEST 2010


"Albert-Jan Roskam" <fomcl at yahoo.com> wrote

> following classes: Menu (responsible for the widget creation), 
> Autocomplete (a
> subclass of the tkinter text entry widget which I've found on the 
> internet, I
> wanted to keep this intact), Convert (responsible for the 
> conversion/cropping of
> the images, which is somewhat tedious) and Events (here's the pain 
> spot: this
> has become a mixed bag). Originally, the Events class was supposed 
> to contain
> all the commands behind the widgets, but it has slowly gotten more
> responsibilities.

That last bit is bad...

> I'd like to rewrite to entire program so that (1) all classes have 
> just one
> responsibility (2) classes connect to as little other classes (so it 
> becomes
> easy to e.g. change to another widget set). I'd love to hear some 
> thoughts or


You need to go back to first principles of GUI design.
Separate the data classes(models) from the behaviour of the GUI 
(controller)
and the display(views)
Read up on the MVC pattern on Wikipedia.
Build the core application code in your models.
Display them in views.
Use a controller(or occasionally controllers) to manage the 
interactions.

HTH,


-- 
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/




More information about the Tutor mailing list