0

I have a web service written in Python that has a class that contains handlers for client requests. Due to protocol complexity the number of handlers is high. All handlers are called inside separate thread (Controller class which is a subclass of Thread). To reduce the class size I've defined handlers in separate modules. The end result is below:

from handlers.main_handlers import delete_project, ...
class Controller(Thread):
    _handle_delete_project = delete_project.handle_delete_project
    ...

    def run():
        while not self._stopped:
            ...
            self._handle_delete_project(...)
            ...

Is there a more Pythonic way do to this? I mean to split a class into multiple files with a better pattern.

Onur A.
  • 3,007
  • 3
  • 22
  • 37
Pavlo
  • 1,594
  • 2
  • 15
  • 30
  • 1
    Do the handlers need to be methods? Why not just make them functions and spread them out over as many files as you like? – Roland Smith Mar 19 '17 at 10:01
  • 1
    Perhaps you'd be better at [codereview.se], where you can provide more context and get more thorough feedback? – jonrsharpe Mar 19 '17 at 10:01
  • @RolandSmithYes, they need to be methods because they need access to context that is part of the Controller object and should be shared between all handlers. – Pavlo Mar 19 '17 at 12:04
  • @jonrsharpeI did not know about Code Review at the moment when I've created this question. But I think this place is also not so bad for such questions. – Pavlo Mar 19 '17 at 12:06
  • 1
    This question is answered by [Is there any Python equivalent to partial classes?](https://stackoverflow.com/questions/9638446/is-there-any-python-equivalent-to-partial-classes). – Mike Robins Aug 24 '17 at 02:40

0 Answers0