[Tutor] Inter-related modules
msp
pinvest at westnet.com.au
Sun May 2 03:15:06 EDT 2004
I have a problem with several modules all needing to use
another module. This is quite common, but I'll use curses
as an example as it's familiar to many.
I start my main program which imports curses and calls initscr().
It asks the user what they want to do, and they select something from
module 'a'. Module 'a' needs to use the screen to interact with the user.
If module 'a' imports curses, this copy of curses knows that initscr()
hasn't been calledand fails. If it calls initscr(), I have two sets of
curses
talking to the screen at once. This may be OK for curses (it saves and
restores the starting screen state) but not for some other modules which
I also have this problem with.
Some might suggest that I have an intermediate interface module so that
all screen i/o is done in one place. This is fine, except that I now
have the
same problem with that module instead.
For some of my own modules (i.e. not curses) I could instantiate a class at
the top level and pass it to everything which needs it. The problem with
this is that the class is unknown at parse time, so errors wouldn't be found
until a piece of code was actually used. This might be months later
for some
obscure bits.
Having a basic moduile which is needed by many others must be a common
problem. How is it normally handled?
More information about the Tutor
mailing list