[Tutor] communication between class instances
Poor Yorick
gp@pooryorick.com
Thu Dec 5 01:00:01 2002
Hi,
I've been studying Python for several months now, and it is my first
attempt to learn how to program in any language. I've been trying
lately to understand some of the nuances of object oriented programming,
but most of the resources on the web require some knowledge of c++ to
gist. So, I'm turning to this list :) Direct answers or pointers to
reference material about this question would be greatly appreciated:
Say I have the following classes:
class app:
def __init(self):
self.dbtype = None
self.gui=gui(self)
class gui:
def __init__(self, app):
self.app = app
self.main_menu = menu(self.app)
class menu:
def __init__(self, app):
self.app = app
def dbtype(self):
app.dbtype = 'metakit'
So far, instantiating classes and passing references to all other class
instances that the instance will need to communicate with is the only
way I've come up with to get class instances to communicate with each
other. This seems unwieldy and not really modular. Is there a better
way to pass data between class instances? One thing I really don't like
is having to pass a reference to the app instance all the way down to
the menu instance, which really should only be aware of the gui instance
which instantiates it. Right?
Right?
I'm very confused...
Poor Yorick
gp@pooryorick.com