python组合数据类型实例_Python:如何在不同类的实例之间共享数据?

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

题:

基本上我有3个类,有很多方法,从代码中可以看出它们有点依赖.如何将BigClassA中的实例变量self.b,self.c,self.d的值共享到BigClassB?

nb:这3个类不能相互继承,因为它没有意义.

我的想法是将所有方法组合成一个超级大班.但我觉得这不是一种正确的方法.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值