Extract shared factory dispatch into ComponentFactory base class

All four name-dispatch factories repeated the same if/elif lazy-import
pattern. Replace with a ComponentFactory base class holding a callable
registry and a _lazy() helper for the common import-and-construct case.
PlantFactory is an orchestrator, not a dispatcher, and is left as-is.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tqxrk8uj4M3w3d3eXm3xK8
This commit is contained in:
2026-06-25 20:44:43 +02:00
co-authored by Claude Sonnet 4.6
parent 47fb09aa06
commit f7355270c8
5 changed files with 48 additions and 36 deletions
+6 -9
View File
@@ -1,11 +1,8 @@
from components.factory import ComponentFactory, _lazy
class HeaterFactory:
@staticmethod
def create(name, *args, **kwargs):
if "sim" in name:
from components.actor.heater_sim import HeaterSim
return HeaterSim(*args, **kwargs)
elif "Hendi" in name:
from components.actor.heater_hendi import HeaterHendi
return HeaterHendi(*args, **kwargs)
class HeaterFactory(ComponentFactory):
_registry = {
"sim": _lazy("components.actor.heater_sim", "HeaterSim"),
"Hendi": _lazy("components.actor.heater_hendi", "HeaterHendi"),
}
+11 -9
View File
@@ -1,11 +1,13 @@
from components.factory import ComponentFactory, _lazy
class StirrerFactory:
@staticmethod
def create(name, dt, params):
if "sim" in name:
from components.actor.stirrersim import StirrerSim
return StirrerSim(dt)
elif "1376" in name:
from components.actor.stirrerpololu1376 import StirrerPololu1376
return StirrerPololu1376(dt, params)
def _sim(dt, params):
from components.actor.stirrersim import StirrerSim
return StirrerSim(dt)
class StirrerFactory(ComponentFactory):
_registry = {
"sim": _sim,
"1376": _lazy("components.actor.stirrerpololu1376", "StirrerPololu1376"),
}