zoukankan      html  css  js  c++  java
  • 针对上一篇文章中的代码,想出的重构方案(python实现)

    #!/usr/bin/env python
    
    class Processor:
        def __init__(self, processor):
            self.processor = processor
            
        def isAllowSend(self, message, setChargeFlag):
            pass
    
    class WhildListProcessor(Processor):
        def isAllowSend(self, message, setChargeFlag):
            if message.sender in (1,2):
                return True
            
            if self.processor != None:
                return self.isAllowSend(message, setChargeFlag)
    
    class DateProcessor(Processor):
        def isAllowSend(self, message, setChargeFlag):
            if message.date > "20130101":
                return False
            
            if self.processor != None:
                return self.isAllowSend(message, setChargeFlag)
               
    
    class DefaltProcessor:
        def isAllowSend(self, message, setChargeFlag):
            setChargeFlag(message)
            return True
        
    def getProcessor():
        return WhildListProcessor(DefaltProcessor(None))
    
    class Message:
        def __init__(self, sender, ):
            self.sender   = sender
            self.isSend   = False
            self.isCharge = False
    
    def setChargeFlag(message):
        message.isCharge = True
    
    def setSendFlag(message):
        message.isSend = True
    
    def run(self):
        message = Message(10)
        processor = getProcessor()
        if (processor.isAllowSend(message, setChargeFlag)):
            setSendFlag(message)
  • 相关阅读:
    Python subprocess方法
    Python hashlib、hmac加密模块
    mysql binlog详解
    Nginx 关键字详解
    账号笔记
    Python configparser模块
    Python yaml处理
    Linux && 与 ||
    spring boot 学习(十一)使用@Async实现异步调用
    spring boot 学习(十)SpringBoot配置发送Email
  • 原文地址:https://www.cnblogs.com/code-style/p/3501713.html
Copyright © 2011-2022 走看看