Functional programming 函数式编程中的策略模式
我正试图使用上面提到的示例,用函数式编程语言(不是纯函数式的,没有对象,没有函数重载)编写一个策略设计模式示例 尽管我知道函数式编程语言中有很多功能都是现成的 在设计模式概念方面,我遗漏了什么吗Functional programming 函数式编程中的策略模式,functional-programming,kdb,strategy-pattern,Functional Programming,Kdb,Strategy Pattern,我正试图使用上面提到的示例,用函数式编程语言(不是纯函数式的,没有对象,没有函数重载)编写一个策略设计模式示例 尽管我知道函数式编程语言中有很多功能都是现成的 在设计模式概念方面,我遗漏了什么吗 :是赋值运算符 文件压缩程序 strategy:`noOp; setCompressionAlgo:{[algo] strategy:algo } compressFiles:{[filesList] strategy[filesList] } 文件压缩程序 zipCompres
:
是赋值运算符
文件压缩程序
strategy:`noOp;
setCompressionAlgo:{[algo]
strategy:algo
}
compressFiles:{[filesList]
strategy[filesList]
}
文件压缩程序
zipCompress:{[fileList]
//compress each file using the zip compression
}
rarCompress:{[fileList]
//compress each file using the rar compression
}
文件压缩程序
zipCompress:{[fileList]
//compress each file using the zip compression
}
rarCompress:{[fileList]
//compress each file using the rar compression
}
文件客户端
start:{[path]
filesList:getFiles[path];
setCompressionAlgo[zipCompress];
compressFiles[fileList]
}
您通常不会使策略成为全局(可变)变量。您可以将示例简化为
start: {[path]
compressFiles: zipCompress;
// change to
// compressFiles: rarCompress
// to use a different strategy
// apply the strategy:
compressFiles[fileList1]
compressFiles[fileList2]
}
“函数式编程语言”——你说的是哪种语言?你能把这个语法的解释链接起来吗?如果你使用一种其他人都不会使用的语言,那么这个问题真的很难回答&