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:
@@ -1,11 +1,8 @@
|
||||
from components.factory import ComponentFactory, _lazy
|
||||
|
||||
|
||||
class PidFactory:
|
||||
@staticmethod
|
||||
def create(name, *args, **kwargs):
|
||||
if "Normal" in name:
|
||||
from components.pid.temp_controller import TempController
|
||||
return TempController(*args, **kwargs)
|
||||
elif "Smith" in name:
|
||||
from components.pid.temp_controller_smith import TempController
|
||||
return TempController(*args, **kwargs)
|
||||
class PidFactory(ComponentFactory):
|
||||
_registry = {
|
||||
"Normal": _lazy("components.pid.temp_controller", "TempController"),
|
||||
"Smith": _lazy("components.pid.temp_controller_smith", "TempController"),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user