Python开发接口

Python本身不提供Interface的创建和使用

安装zope.interface

pip install zope.interface

 

 

interface_demo.py

 

 代码:

from zope.interface import Interface
from zope.interface.declarations import implementer

#定义接口
class IHost(Interface):
def sayHello(self, host):
"""Say Hello to host"""

@implementer(IHost) #继承接口
class Host:
def sayHello(self, guest):
return "Hi %s:" % guest

if __name__ == '__main__':
host1 = Host()
hello = host1.sayHello('Jake')
print(hello)
posted @ 2019-11-29 11:52  JakeYu  阅读(92)  评论(0)    收藏  举报