중 하나의 방법을 사용하여 I가 다음 코드를 왜 여전히 A.PickTarget
에 useA=False
와 C.Update
를 호출을다중 상속 및 기본 클래스
class A(object):
def __init__(self):
self.name = "A"
super(A, self).__init__()
def Update(self):
print "Update A"
self.PickTarget()
def PickTarget(self):
print "PickTarget A"
class B(object):
def __init__(self):
self.name = "B"
super(B, self).__init__()
def Update(self):
print "Update B"
self.PickTarget()
def PickTarget(self):
print "PickTarget B"
class C(A, B):
def __init__(self):
super(C, self).__init__()
def Update(self, useA):
if useA:
A.Update(self)
else:
B.Update(self)
c = C()
c.Update(useA = True)
# prints:
# Update A
# PickTarget A
c.Update(useA = False)
# prints:
# Update B
# PickTarget A
를 호출합니까? 내가 어떻게 작동하게 할 수 있습니까? (예 : B.Update는 항상 B.PickTarget을 호출합니다) 나는 이것이 전에 질문 받았다고 확신하지만 아무것도 찾지 못했다. 아마도 내가 무엇을 검색해야할지 모르겠다.
여전히 재 설계가 필요하다고 생각되지만,이 글에서는 이름 맹 글링이이 문제에 대해 상당히 유연한 해결책을 제공한다는 점을 지적 할 것입니다. [내 편집] (http://stackoverflow.com/questions/6849519/multiple-inheritance-and-using-a-method-of-one-of-the-base-classes/6849613#6849613)을 참조하십시오. – senderle