1.7 KiB
1.7 KiB
modular_controller_pattern — v1
Why this iteration: Lifted verbatim from conductor/product-guidelines.md §"Code Standards & Architecture" (line 40) + conductor/code_styleguides/python.md §15 (lines 234-240). This is the baseline encoding — the imperative-bullet style currently in production.
Future variants will test alternative encodings (rationale-first, tabular) against this baseline.
Source: conductor/product-guidelines.md:40 + python.md:234-240
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.