initialization

How to perform common post-initialization tasks in inherited classes?

老子叫甜甜 提交于 2020-11-26 12:16:32
问题 The initialization process of a group of classes that share a common parent can be divided into three parts: Common initialization Subclass-specific initialization Common post-initialization Currently the first two parts are called from the __init__ method of each child class, but the final post-initialization part has to be called separately, for example class BaseClass: def __init__(self): print 'base __init__' self.common1() def common1(self): print 'common 1' def finalizeInitialization

How to perform common post-initialization tasks in inherited classes?

。_饼干妹妹 提交于 2020-11-26 12:16:04
问题 The initialization process of a group of classes that share a common parent can be divided into three parts: Common initialization Subclass-specific initialization Common post-initialization Currently the first two parts are called from the __init__ method of each child class, but the final post-initialization part has to be called separately, for example class BaseClass: def __init__(self): print 'base __init__' self.common1() def common1(self): print 'common 1' def finalizeInitialization