I'm doing scientific computations using Python.
So far I have a module core and a class Simulation inside. There are many instances of Simulation at the runtime but all of them must share the same "problem setup". So far this problem setup is represented by global variables and functions in the module core with sophisticated initialization logic.
For various reasons I think the program architecture would benefit from refactoring in the following way:
- there is a class
Problemand the only instance of it - all the initialization logic is encapsulated in
Problem.__init__ - all the instances of
Simulationare connected to the sameprobleminstance
What I have the following implementation using class variables in mind:
class Problem:
def __init__(self, ...)
# sophisticated logic moves here
...
class Simulation:
... various methods relying on self.problem ...
Simulation.problem = Problem(...)
s1 = Simulation(...)
s2 = Simulation(...)
...
What are the best practices to do something like this?