I am looking for some help on organizing some code for a physics simulator. I want to know if this design structure is "ok" , if theres a name for it, or any better ways to structure my code.
Basically my code is composed of many components that eventually get called in essentially a pipeline: basically one MySim.run at the end of the day. I rely on duck typing checked by protocols to swap out components where appropriate. I treat each class as an immutable function call. Most of the classes are dataclasses, but not necessarily.
My Concern is that it feels weird to simply make these objects to use once and throw away. I am also just looking to see if this pattern has a name so I can go find other implementations and maybe find some blindspots.
It does seem like ETL: my concern with ETL libraries is it feels like they simply invented a new programming language in JSON or whatever that I rather not bother with.
@dataclass
class SubComponentA:
size: float
weight: float
def run_component(self, a, b, c):
...
@dataclass
class SubComponentB:
temperature: float
speed: float
def run_component(self, x, y):
...
@dataclass
class ComponentA:
heavy_thing: SubComponentA
fast_thing: SubComponentB
def run_component(self, a, b, c):
x, y = self.heavy_thing.run_component(a, b, c)
return self.fast_thing.run_component(x, y)
@dataclass
class ComponentB:
...
@datclass
class MySim:
part_A: ComponentA
part_B: ComponentB
def run(self, a, b, c):
... = self.part_A.run_component(a, b, c)
return self.part_B.run_component(...)