知识卡片
近似闭包也能降低认知负担
严格闭包要求操作的参与类型与返回类型处于同一概念集合;若额外参数是编程环境里人人熟悉的基础类型,仍可得到部分好处,但应称“近似”,不能误报为严格闭包。
原书的集合选择教学例子:Java 用 Iterator 遍历、测试并累积子集,引入额外机制;Smalltalk 的 Collection.select(block) 返回新 Collection,便于串接过滤。由于 block 也是参数,它不是严格闭包;但在 Smalltalk 中 block 属于基础库概念,对读者的额外负担较小。接口是否更清楚,应按用户要表达的“选择子集”来评估。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- 原书第10章|Closure of Operations · 查看原书依据
The Smalltalk Collections provide other such FUNCTIONS that return derived Collections, which can be of several concrete classes. The operations are not closed, because they take a "block" as an argument. But blocks are a basic library type in Smalltalk, so they don't add to the developer's mental load.
参考来源
- 位置:《Domain-Driven Design: Tackling Complexity in the Heart of Software》第78章《Closure of Operations》(源文件:_epub-src/0321125215_ch10lev1sec6.html;单元02)
- 结论依据:原文对比 Java Iterator 与 Smalltalk Collection.select,明确后一操作因 block 参数而不严格闭包,但基础库参数仍让同类结果易于串接。
- 原始内容:The Smalltalk Collections provide other such FUNCTIONS that return derived Collections , which can be of several concrete classes. The operations are not closed, because they take a "block" as an argument. But blocks are a basic library type in Smalltalk, so they don't add to the developer's mental load.