My project structure is the following
|-- project/
|-- run.py
|-- classes/
|-- module_defining_class_a.py [=> class classA():...]
|-- module_defining_class_b.py [=> class classB():...]
|-- config.yaml
where run.py
initializes a ClassA
object, which in turn initializes a ClassB
object.
Now run.py
also parses a command line argument pointing to a config.yaml
file. The dictionary that results from parsing this .yaml
file contains keys and values that are required by both ClassA
and ClassB
when they are initialized.
My question is: How can I best share this command line argument across both classes?
The obvious solution would be to pass it to the __init__
method of ClassA
and have it pass the config
dictionary on to the __init__
method of ClassB
; but this feels unelegant because the argument would then be passed down in a waterfall-like manner. I would much rather be able to access the command line argument from within each class when instantiating it, without passing it to the __init__
method repeatedly as an argument.
Am I correct in assuming that passing the argument down via multiple levels is not good design? If so, what could be a better solution?