1.3 KiB
1.3 KiB
State-independent logic must be moved to module-level functions (avoid god-object controllers)
From conductor/product-guidelines.md §"Code Standards & Architecture":
- Modular Controller Pattern: To prevent "God Object" bloat in core controllers (like
AppController), all state-independent or utility logic must be moved to module-level functions. Functions requiring class state should accept the instance as an explicit dependency (def logic(controller: AppController, ...)). Massiveif/elifdispatch blocks must be refactored into handler maps (dictionaries) of module-level functions.
From conductor/code_styleguides/python.md §15:
15. Modular Controller Pattern
To prevent "God Object" bloat in core controllers (like AppController):
- Extract Logic: Move all state-independent or purely utility logic to module-level functions.
- Dependency Injection: Module-level functions that require class state should accept the instance as their first argument (e.g.,
def my_extracted_logic(controller: AppController, ...)). - Handler Maps: Replace massive
if/elifblocks (like those in event dispatchers) with dictionaries mapping keys to module-level handler functions. - Inner Class Extraction: Never define nested classes or functions within methods. Move them to the module level.