software design question

Uwe Mayer merkosh at hadiko.de
Sat Feb 7 13:16:05 CET 2004


Hi,

I have the following inter-class relationships:

__main__:  (in file LMCMain.py)
  imports module FileIO
  defines class LMCMain 
  instanciats main = LMCMain(...)

FileIO.py:
  defines class FileIO
  class FileIO needs to access "main" from LMCMain.py

In FileIO.py I've tried to "import LMCMain", but that causes the main
program to be re-executed. I only wanted to access to the main class
instance LMCMain.
My aim is a modular software design. I know this yields much communication
overhead and may become compilcate soon. Here I rely on "its not too slow"
and eventually perhaps psyco. 

A solution I could think of would be a Singleton. Both LMCMain.py and
FileIO.py import "singleton.py". LMCMain.py stores "main" in singleton and
FileIO.py accesses it.
I could also use a static class instead of a public module variable... I
don't really know whats better.

I'd like to fall back on some design pattern, but somehow you can only use
them, once you're used to them (i.e. theoretical knowledge does not
suffice).
I also learned much from the "logging" module and the Qt SIGNAL-SLOT concept
which IMO are excellently designed.

I know this is not strictly related to Python, but since I'm working in
Python I'd like to hear pythoneers suggestion to it.

Thanks in advance
Uwe



More information about the Python-list mailing list