Python: como compartilhar dados entre instâncias de diferentes classes?
Class BigClassA:
def __init__(self):
self.a = 3
def foo(self):
self.b = self.foo1()
self.c = self.foo2()
self.d = self.foo3()
def foo1(self):
# do some work using other methods not listed here
def foo2(self):
# do some work using other methods not listed here
def foo3(self):
# do some work using other methods not listed here
Class BigClassB:
def __init__(self):
self.b = # need value of b from BigClassA
self.c = # need value of c from BigClassA
self.d = # need value of d from BigClassA
def foo(self):
self.f = self.bar()
def bar(self):
# do some work using other methods not listed here and the value of self.b, self.c, and self.d
Class BigClassC:
def __init__(self):
self.b = # need value of b from BigClassA
self.f = # need value of f from BigClassB
def foo(self):
self.g = self.baz()
def baz(self):
# do some work using other methods not listed here and the value of self.b and self.g
Pergunta: Basicamente, eu tenho 3 classes com muitos métodos e elas são um pouco dependentes, como você pode ver no código. Como compartilho o valor das variáveis de instância self.b, self.c, self.d de BigClassA para BigClassB?
Nota: essas três classes não podem ser herdadas uma da outra, pois não faz sentido.
O que tenho em mente é apenas combinar todos os métodos em uma classe super grande. Mas não acho que essa seja a maneira correta de fazê-lo.