def _add_class_type(cls, type, inits, proxied): def setter(self, xcls):
setattr(self, type + '_class', xcls)
for m in inits:
self.mdic[m] = xcls
for m in proxied:
if hasattr(xcls, m):
self.mdic[m] = self.proxyclass(m)
1 回答

慕桂英546537
TA貢獻(xiàn)1848條經(jīng)驗(yàn) 獲得超10個(gè)贊
你漏了一行代碼,這個(gè)方法是
def _add_class_type(cls, type, inits, proxied): def setter(self, xcls): setattr(self, type + '_class', xcls) for m in inits: self.mdic[m] = xcls for m in proxied: if hasattr(xcls, m): self.mdic[m] = self.proxyclass(m) setattr(cls, 'set_' + type + '_class', setter)
這個(gè)方法簡單來說,就是把基礎(chǔ)類和其他類的方法映射為本對象的方法,類似一個(gè)FACADE。
添加回答
舉報(bào)
0/150
提交
取消