代码优化,设计模式

const result = {
    resultA: "...",
    resultB: "...",
    resultC: "...",
    resultD: "...",
    resultE: "...",
}

const stateEnums = {
    stateA: "stateA",
    stateB: "stateB",
    stateC: "stateC",
}

const categoryEnums = {
    categoryA: "categoryA",
    categoryB: "categoryB",
    categoryC: "categoryC",
    categoryD: "categoryD",
    categoryE: "categoryE",
}

const otherEnums = {
    otherA: "otherA",
    otherB: "otherB",
    otherC: "otherC",
    
}



function execute(state, category, ...rest) {
    if(state === stateEnums.stateA) {
        if(category  === categoryEnums.categoryB) {
            return result.resultD
        }else {
            return result.resultC
    }
    }else {
        
    }
    if(state === stateEnums.stateB) {
    
    }
}

// 
/**
* enums 的类型可能拓展
* 选择enumes判断可能是一个或者多个
* 有什么好的方式实现更合理,易于拓展 rest 科恩那个不断变多
* 设计模式? 桥接模式?
*/
阅读 730
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题