Design question.... parent/child class

Gumuz gumuz at looze.net
Tue Sep 3 17:15:42 CEST 2002


I'm sorry, I don't think I understand it correctly.

Do you mean i should create a third Interface class just to communicate to
the other class? Isn't that then just the same but with an extra class?

"Peter Hansen" <peter at engcorp.com> wrote in message
news:3d74b283$1 at news.sentex.net...
> Gumuz wrote:
> > hi all,
> >
> > i have a SessionManager class, which contains a list of Session
> > objects(instantiated from a Session class). I have a design problem.
> >
> > Each session object has a small 'queue' of messages for the specific
> > session. How can a session send a message to another session without
having
> > some kind of parent-reference to the SessionManager object?
> >
> > i am a bit puzzled, or is this parent-reference not such a bad idea
after
> > all?
>
> Increasing coupling is always bad, but you could do this in a way that
> doesn't really increase coupling (at least in Python).  The Session
> objects don't need to know about SessionManagers specifically, just
> about some thing that has a particular interface.  In this case, maybe
> it's a "post" method.  Pass in a reference to the SessionManager,
> or even the post method itself (a "bound" method, bound to a specific
> SessionManager instance), but don't do an "import sessionmanager"
> or anything like that in the session.py module itself.
>
> Note that passing messages between Sessions could be considered a
> function not appropriate for something called merely "SessionManager".
> Maybe you want to do this with another mechanism in parallel to this,
> or rename that class.  Personally, I wouldn't do that unless the
> whole design was starting to get complex.
>
> -Peter
>





More information about the Python-list mailing list