# Highmiddlelow.py Copyright (c) Kari Laitinen # http://www.naturalprogramming.com # 2006-05-06 File created. # 2022-12-18 Converted to Python 3. # It seems that the rule in Python is that the constructor # of the immediate superclass is not called automatically # if "this" class, i.e., the class that is being instantiated, # has a constructor. If there is no constructor in "this" # class, the constructor of the immediate superclass is # executed because the constructor, i.e., the __init__() # method, is inherited. # In the class hierarchy below, the constructors of superclasses # are called from the low class constructors. class MemberClass : def __init__( self, object_identifier ) : print( "\n MemberClass object \"%s\" was created." % \ object_identifier, end="" ) class HighClass : def __init__( self ) : print( "\n The constructor of HighClass started.", end="" ) self.some_data_member = MemberClass( "some_data_member" ) self.another_data_member = MemberClass( "another_data_member" ) print( "\n The constructor of HighClass ended.", end="" ) class MiddleClass ( HighClass ) : def __init__( self ) : print( "\n The constructor of MiddleClass started.", end="" ) HighClass.__init__( self ) # calling the superclass constructor print( "\n The constructor of MiddleClass ended.", end="" ) class LowClass ( MiddleClass ) : def __init__( self ) : print( "\n The constructor of LowClass started.", end="" ) MiddleClass.__init__( self ) # calling the superclass constructor self.data_member_in_low_class = MemberClass( "data_member_in_low_class" ) print( "\n The constructor of LowClass ended.", end="" ) # The main program. low_class_object = LowClass() # # The author of this program has done his best to ensure the accuracy of # information presented in this source program file. However, # the author assumes no responsibility for errors in this program. # The author shall not be liable in any event for incidental or # consequential damages in connection with, or arising out of, # any kind of use of this program or other information provided at # the Internet site naturalprogramming.com #