OO design, Python, and GUIs

Peter Maas fpetermaas at netscape.net
Tue Nov 18 08:50:35 EST 2003


Christopher Culver schrieb:
> I'm creating a home-library management program with Python 2.2, PyGTK, and
> Glade. While I've been many little programs before, this is my first large
> application in Python. My question is how I should organise the OO design
> of such a program. There should be, I gather, a core class "MainClass",
> which coordinates everything, other specialised classes which report to
> MainClass, and the GUI should ideally be in its own class "GuiClass".

There is a start up module that will talk to you first, I'd call it
homelib.py. It does the necessary initialisations like loading the
GUI resources, opening the database etc. If you want to encapsulate
this in a class you could call it main or start. I wouldn't give the
feature providing classes generic names like "main". They do something
special, so I would give them names that tell something about their
resonsibilities, e.g. library, libraryItem, book, magazine, storage,
editView, listView etc. Aggregate related classes in a module, related
modules in a package (if you have lots of modules).

The feature modules would be imported by the start up module. It
wouldn't be bad to have a rough plan of your software before you
start to write code. The building blocks (packages, modules) of
your app have "uses" relations. If module a uses b then a has to
import b. A layered approach would probably be helpful:

u |   startup, user interface
t |-------------------------------
i | engine (provides the features)
l |-------------------------------
s | storage (file, db, network)

Each layer uses its neighbour below, all layers use utils. The layers
could be distributed across several programs (multi-tiered app) but
that's not necessary, of course.

Mit freundlichen Gruessen,

Peter Maas

-- 
-------------------------------------------------------------------
Peter Maas, M+R Infosysteme, D-52070 Aachen, Hubert-Wienen-Str. 24
Tel +49-241-93878-0 Fax +49-241-93878-20 eMail peter.maas at mplusr.de
-------------------------------------------------------------------





More information about the Python-list mailing list