首页 > 解决方案 > 我如何知道在 Python 3 中将调用哪个方法?

问题描述

我的练习中有这些课程:

class A:
    def accept(self,v):
        v.visitA(self)
class B(A):
    def accept(self,v):
        v.visitB(self)
class C:
    def accept(self,v):
        v.visitC(self)
class Visitor:
    def visitA(self,x):
        return x.accept(self)
    def visitB(self,x):
        pass
    def visitC(self,x):
        pass

我的问题是,x.accept(self)在访问者类的方法 visitA 中可以(间接)调用访问者类的哪个方法?尽管阅读了有关 python 继承的信息,但我并不真正理解这些代码。有没有人可以帮我解释这段代码?先感谢您!

标签: pythoninheritance

解决方案


推荐阅读