适配器模式,适配不同方法的类。
class ClassB(object):
def __init__(self):
pass
def need_method(self):
pass
class ClassA(object):
def __init__(self):
pass
def need_method_other_name(self):
pass
class Adapter(object):
def __init__(self, cls):
self.instance = ClassA()
def need_method(self):
self.instance.need_method_other_name()
def main():
[x.need_method() for x in [Adapter(ClassA), ClassB()]]
if __name__ == '__main__':
main()