Python class design - Splitting up big classes into multiple ones to group functionality
Posted
by Ivo Wetzel
on Stack Overflow
See other posts from Stack Overflow
or by Ivo Wetzel
Published on 2010-03-24T03:34:35Z
Indexed on
2010/03/24
3:43 UTC
Read the original article
Hit count: 559
OK I've got 2 really big classes > 1k lines each that I currently have split up into multiple ones. They then get recombined using multiple inheritance. Now I'm wondering, if there is any cleaner/better more pythonic way of doing this. Completely factoring them out would result in endless amounts of self.otherself.do_something
calls, which I don't think is the way it should be done.
To make things clear here's what it currently looks like:
from gui_events import GUIEvents # event handlers
from gui_helpers import GUIHelpers # helper methods that don't directly modify the GUI
# GUI.py
class GUI(gtk.Window, GUIEvents, GUIHelpers):
# general stuff here stuff here
One problem that is result of this is Pylint complaining giving me trillions of "init not called" / "undefined attribute" / "attribute accessed before definition" warnings.
© Stack Overflow or respective owner