classComputer:def__init__(self, name):
self.name = name
def__str__(self):return'the {} computer'.format(self.name)defexecute(self):return'executes a program'classSynthesizer:def__init__(self, name):
self.name = name
def__str__(self):return'the {} synthesizer'.format(self.name)defplay(self):return'is playing an electronic song'classHuman:def__init__(self, name):
self.name = name
def__str__(self):return'{} the human'.format(self.name)defspeak(self):return'says hello'classAdapter:def__init__(self, obj, adapted_methods):
self.obj = obj
self.__dict__.update(adapted_methods)def__str__(self):returnstr(self.obj)if __name__ =='__main__':
objects =[Computer('Asus')]
synth = Synthesizer('moog')
objects.append(Adapter(synth,dict(execute=synth.play)))
human = Human('Bob')
objects.append(Adapter(human,dict(execute=human.speak)))for i in objects:print('{} {}'.format(str(i), i.execute()))print('type is {}'.format(type(i)))