zoukankan      html  css  js  c++  java
  • 责任链模式

    class Manager(object):
        # 设置管理者的上级
        def set_superior(self,successor):
            self.successor = successor
        def request(self,req):
            pass
    class CommonManager(Manager):
        def request(self,req):
            if req > 0 and req < 3:
                print("%s 经理处理"%req)
            else:
                return self.successor.request(req)
    class Majordomo(Manager):
        def request(self, req):
            if req > 3 and req < 10:
                print("%s 总监处理" %req)
            else:
                return self.successor.request(req)
    class GeneralManager(Manager):
        def request(self, req):
            if req >= 10:
                print("%s 总经理处理" %req)
    if __name__ == '__main__':
        h1 = CommonManager()
        h2 = Majordomo()
        h3 = GeneralManager()
        # 设置责任链
        h1.set_superior(h2)
        h2.set_superior(h3)
        # 提交申请
        h1.request(2)
        h1.request(20)
        h1.request(7)

  • 相关阅读:
    consumer详解
    消费幂等
    死信队列
    消息重试
    负载均衡
    存储层
    producer消息
    消息发送与接收
    TCC
    form表单提交前进行加密
  • 原文地址:https://www.cnblogs.com/hanqian/p/7044940.html
Copyright © 2011-2022 走看看