memoization 可以被视为一种设计模式还是仅仅是一种缓存方法?
最佳答案
在实际意义上,设计模式通常定义多个相对复杂的类/对象如何交互。甚至 Singleton [反] 模式也不仅描述了创建对象的方式,还描述了其他对象如何使用它......
相反,内存更像是一种编码技术。虽然它经常在底层使用某种 map /字典对象,但该对象可以是本地的、特定于语言的对象,而不是自定义的特定于域的对象或了解上下文的专门/优化的手工对象。因此,没有太多的设计实现细节。
因此,IMO 的关键决定性差异是所涉及的抽象级别,在设计模式的情况下更高,而在记忆化、函数组合、柯里化(Currying)等编码技术方面则非常低。不过,这是一个定义问题。
维基百科:
... a software design pattern is a general reusable solution to a commonly occurring problem within a given context in software design.
...
Design patterns may be viewed as a structured approach to computer programming intermediate between the levels of a programming paradigm and a concrete algorithm.
然而,
memoization or memoisation is an optimization technique used primarily to speed up computer programs by storing the results of expensive function calls and returning the cached result when the same inputs occur again.
关于javascript - 什么是记忆化?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47909473/