ok, i have started doing this with my 4000 + line file. So far its been
working out.
i have another question about it.

i have two classes in my program that use a global object that is a socket
connection.

example:
global  my_sockobj
serverhost = 'mehost.com'
serverport = 9100
my_sockobj = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
my_sockobj.connect((serverhost,serverport))

then i use my_socket.recv to get stuff from the socket in one class
and my_socket.send to send stuff from another class.

is there something tricky about passing this as a global object to different
modules that would need to use it?
Or does this go along with what you wrote a while back about having classes
that depend on each other ?

One runs as a thread, the other responds to gui input.

thanks for any tips.

shawn

On 12/31/06, Alan Gauld <[EMAIL PROTECTED]> wrote:

"shawn bright" <[EMAIL PROTECTED]> wrote

> Yes, the thing is getting to be a pain to deal with at this size, i
> am
> in-process of splitting out the classes into their own files.

One thing to watch is that while its easy and tempting to create
one file per class it's often better to keep dependant classes
together.
In other words if class A can only be used together with class B
then it is often better to keep A and B in the same module.
Anyone who needs B can import the module and anyone who
needs A needs B too so it saves them having to import two
modules.

As in all things in programming a little bit of thought is often
better than the first "obvious" strategy. Grady Booch described
the above strategy by saying that "the unit of reuse is the category"
(which in his OO notation was a set of related classes) and in
Python that means the module.

Regards,

Alan G.


_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to