I have a huge class (>1000 lines), in which all methods depend on a small set of attributes in that class. I can think of 2 quick ways of refactoring.
I keep it as a huge object, but split related methods into separate classes from which I inherit (but I don't instantiate those separate classes, only the last one in the inheritance-chain). This probably has the disadvantage that conceptually, my object is still a huge monolith.
I make the common attributes, with a few helper functions, into a separate class. All other code that depends on this common state then are in their own class, but contain the common state through composition. Disadvantage is I end up with a lot of nested lookup calls similar to
self.commonState.foo
, instead of justself.foo
.
The latter is getting a bit reminiscent of the MVC pattern of course. Is there a clear answer to which method is preferred?