← 返回起始笔记位置

知识卡片

普通读书笔记卡 · 1866.a.12

策略替换集中算法差异

理解等级:高级

策略模式把多种算法分别封装,运行时按情境选择;测试可选择带额外状态输出或检查的实现,让主类不混入所有测试分支。少量简单分支可能不值得增加抽象,运行时选择也可能改变所测行为,应明确测试的是哪种策略及其边界。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    • 可测试性 · 查看原书依据

      This pattern is often used to replace non-test versions of some functionality with test versions that provide additional outputs, additional internal sanity checking, and so forth. Benefits: • This pattern makes classes simpler, by not combining multiple concerns (such as different algorithms for the same function) into a single class.

    参考来源

    - 位置:《Software Architecture in Practice, 4th Edition》第12章《可测试性》(来源项目:book-sources;源文件:extracted/Software Architecture in Practice, 4th Edition/_epub-src/ch12.html) - 结论依据:所引连续原文给出本卡机制或取舍;条件与示例结合本节已读上下文解释。 - 原始内容:This pattern is often used to replace non-test versions of some functionality with test versions that provide additional outputs, additional internal sanity checking, and so forth. Benefits: • This pattern makes classes simpler, by not combining multiple concerns (such as different algorithms for the same function) into a single class.