Python adapter


#coding=utf-8
class Target(object):
def specific_request(self):
return 'Hello Adapter Pattern!'

# object adapter
class Adapter(object):
def __init__(self, adaptee):
self.adaptee = adaptee
def request(self):
return self.adaptee.specific_request()

#class Adapter ,direct
class ClassAdapter(Target):
def request(self):
return self.specific_request()

#class Adapter,mixin
class T(object):
def request(self):
return self.specific_request()
class AdapterMix(T,Target):
pass

if __name__ == "__main__":
c1 = Adapter(Target())
print c1.request()

c2 = ClassAdapter()
print c2.request()

c3 = AdapterMix()
print c3.request()
阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页