- 我可以使用哪些基本代码(S3、S4)/包(proto、R.oo)来复现例如Gamma等人所述的设计模式?
- 是否有R中实现设计模式的示例,无论是在基本R中还是在包中?
设计模式的一些示例:
The system.time()
function seems to behave much like a decorator pattern. However, almost exclusively decorators are mentioned in the context of object oriented programming. But still, it has the feel of a decorator, it extends (or decorates) an existing piece of code (in OOP always an object) with additional functionality without any need to change the piece of code. Here system.time()
is shown in action:
system.time(bla <- Sys.sleep(1000))
@jverzani posted an example of singleton pattern on github.
apply
family of functions. The functionality of looping over the given object is generic, the function that is applied (the strategy) is chosen when the user supplies the function.
memoise
包可以更轻松地完成这个任务,但我确实有一个使用案例。这个结构的基本思想来自《Head First》书籍。 - jverzani