浏览 1392 次
锁定老帖子 主题:Python adapter
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2008-06-17
#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() 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |