In Python, is there a way to call a commonly named method for all instances of a class, including inheritance-related class instances? Using the example below, when c.process() is called, I would like all "process" methods for all Parent-related instances to trigger. As such, I would want the output to print "Parent process" and "ChildType1 process" for instance c, "Parent process" and "ChildType1 process" for instance d, and "Parent process" and "ChildType2 process" for instance e -- all simply by making one call (perhaps "c.process()", for example). Or this there another architecture to achieve similar means--perhaps using arrays of class instances? Thanks!
class Parent:
def __init__(self):
pass
def process(self):
print("Parent process")
class ChildType1(Parent):
def __init__(self):
super().__init__()
def process(self):
print("ChildType1 process")
class ChildType2(Parent):
def __init__(self):
super().__init__()
def process(self):
print("ChildType2 process")
c = ChildType1()
d = ChildType1()
e = ChildType2()
c.process()