码迷,mamicode.com
首页 > 编程语言 > 详细

在python中使用接口

时间:2015-12-09 19:31:56      阅读:232      评论:0      收藏:0      [点我收藏+]

标签:

#运行环境:python3.5
from abc import ABCMeta,abstractmethod
class IQueue(object,metaclass=ABCMeta):#设置为抽象类
    @abstractmethod #设置为抽象方法,如果子类没有实现此方法,将会报错
    def push(self):
        pass
    @abstractmethod
    def pop(self):
        pass

class RedisQueue(IQueue):
    def __init__(self):
        print(this is interface implement\n)
    def push(self):
        print(RedisQueue push\n)
    def pop(self):
        print(RedisQueue pop\n)

if __name__ == "__main__":
    queue=RedisQueue()
    queue.push();
    queue.pop()

 

在python中使用接口

标签:

原文地址:http://www.cnblogs.com/pycrawler/p/5033435.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!