OO design, Python, and GUIs

Kevin Dahlhausen kdahlhaus at yahoo.com
Tue Nov 18 10:46:14 EST 2003


> 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. 

One solution is to use a layered architeture:

   .---------------.
   |  Presentation |
   '------+--------'
          |
   .---------------.
   |  Application  |
   '------+--------'
          |  
   .---------------.
   |  Persistence  |
   '---------------'

Each layer would be a python package (or multiple
packages if your app is large).  The presentation
layer contains your gui classes. The application
layer contains classes that implement the behavior
of the application.  The persistence layer handles
storage of your domain objects.  Some people would
add a 'domain layer' between the application and
the persistence layer. I suppose that depends on
the size of your project, but for something small
it's overkill and your domain objects are very
likely generated by an oo-rdb mapper tool anyway.

People have differing opinions over whether or not
your gui classes should directly make use of the
domain classes.  Technically, layers in this
architecture should not know about layers other
than the immediate one above or below.  Java
people like to create structures to pass data
between layers.  I think it's not a very good use
of time and prefer to use the domain objects - the
domain should be one thing not changing that much
(a book's a book, right)?

A decent discussion of this architecture is at:
http://www.therationaledge.com/content/oct_01/t_layeringStrategies_pe.html

The best thing to pull from this is to keep the gui 
stuff in its own package python package and put
a little effort into keeping the gui out of
your main application code.  This will give you
more options in the future - perhaps you'll find
you'd like a web version of the library,  or that
FLTK is a sharper looking gui, or you'd like have
a text reader read the list.




More information about the Python-list mailing list