Let's say I have two classes A
and B
, both class needs to maintain fairly complex internal states, and the behavior changes with command line arguments provided:
ARGS = [arg1, arg2, arg3]
/ \
/ \
class A: class B
def __init__(self, key1=arg1, key2=arg2 ...)
self.state1 = blah ...
self.state2 = blah ...
I have two questions:
(1) I could initialize object with different behavior through key=val
argument list, but this long list soon become clumsy. I could also change state directly, is there any rationales or rules I should follow here?
(2) Since both class A
and B
needs access to command line options as well as other switches, for now, there is a global G:
class G:
self.opt1 = True
self.opt2 = False
...
which essentially maintain the shared state and accessible to all parties of interests? Is this a acceptable design or something to be frowned upon? TIA