Design question.... parent/child class

Carl Banks imbosol at vt.edu
Tue Sep 3 14:39:25 EDT 2002


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?


If you can, make the function that transfers a message a member of
SessionManager class, instead of Session.  (Or, if that's not how your
program is set up, have the function that transfers a message take
your SessionManager instance as an argument, or something like that.
The idea is to access the sender or receiver through the
SessionManager class.)

If you can't, think about how easy it would be to change your code so
that you could.  And if it's not too hard, do it.



Abstractly, you want to operate on two siblings in your hierarchy.
You should want to take advantage of the hierarchy; therfore, your
operation should belong to the parent, which contains both sibling
nodes.  If you want to do this operation without the help of then
parent, then you're circumventing (or at least not taking advantage
of) the hierarchy structure.



-- 
CARL BANKS
http://www.aerojockey.com



More information about the Python-list mailing list