Split class across multiple files
Carl Banks
pavlovevidence at gmail.com
Fri Nov 20 11:36:15 EST 2009
On Nov 20, 8:14 am, "eric.frederich" <eric.freder... at gmail.com> wrote:
> I have a class which holds a connection to a server and a bunch of
> services.
> In this class I have methods that need to work with that connection
> and services.
>
> Right now there are about 50 methods some of which can be quite long.
> From an organizational standpoint, I'd like to have method
> implementations in their own files.
>
> Is this possible?
Yes, define all your different methods in separate classes in separate
files. Then subclasses all of those separate classes into one big
class.
> It is recommended?
Debateable. Personally, I have no problem using inheritance for
purely mechanical reasons. Others might. (In my case, it was a
separation into general and customized behavior. I wanted to define
generic behavior in one package, and specialized behavior in another,
but there was no internal logical difference between specialized and
generic methods.) However....
> Should I just stop worrying
> about it and have a 5,000 line class?
Five thousand lines is pushing the comfort level of how big a class
ought to be. I suggest instead of worrying about how to mechanically
split off methods into different files, you should consider whether
there's a way to refactor that one big class into smaller ones. Then
the problem you have goes away.
Carl Banks
More information about the Python-list
mailing list