class
PythonBase:
class BaseClass(object):
def a():
"""This method uses method b(), defined in the inheriting class"""
还有一个继承BaseClass
的类:
class UsedByUser(BaseClass):
def b():
"""b() is defined here, yet is used by the base class"""
我的用户只会创建UsedByUser
类的实例。典型的用法如下:
if __name__ == '__main__':
# initialize the class used by the user
usedByUser = UsedByUser()
# invoke method a()
usedByUser.a()
我的问题是,上述用法是否有问题?这是一种有效的方法,还是必须在BaseClass
中定义b()
方法,然后在UsedByUser
中覆盖它?