论坛首页 入门技术论坛

Python adapter

浏览 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()

论坛首页 入门技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics