天天看點

Python中接口設計的相關包(zope.interface)

zope.interface安裝包下載下傳位址:​​https://pypi.python.org/pypi/zope.interface#downloads​​

使用zope.interface的執行個體:

#coding=utf8
from zope.interface import Interface, implements
class addClass:
    def add(self,a,b):
        """comments"""

class overAdd():
    implements(addClass)
    def add(self,a,b):
        print a+b      

或者

#coding=utf8
from zope.interface import Interface, implements
class addClass:
    def add(self,a,b):
        """comments"""

@implementer(addClass):
class overAdd(): 
    def add(self,a,b):
        print a+b