知识卡片
用萌芽与包裹改动遗留代码
难以直接测试的遗留方法可用萌芽法:把新功能写在别处并测好,再接入旧方法;或用包裹法:保留旧逻辑,在同名新方法中调用重命名的旧方法并加入新逻辑。两者都把改动压在可识别的接缝。
这张卡片看不懂?
这张卡片的反馈已满 10 条,暂时无法继续提交。
已有反馈 · 0 / 10 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- · 查看原书依据
The sprout technique is covered in Michael Feather’s 2004 Working Effectively with Legacy Code. It is often very difficult to unit test code that wasn’t built with testing in mind. Sprout involves creating the new functionality elsewhere, testing it and adding it to a legacy method known as the insertion point. Another technique is to wrap the existing functionality by creating a new method
参考来源
- 位置:《Mastering API Architecture》第8章《Redesigning Applications to API-Driven Architectures》之《Breaking Dependencies: Highly Coupled APIs》(源文件:_epub-src/OEBPS/ch08.xhtml)
- 结论依据:原文分别说明 sprout 在旧方法插入已测试的新功能,以及 wrap 通过新方法调用重命名的旧实现。
- 原始内容:The sprout technique is covered in Michael Feather’s 2004 Working Effectively with Legacy Code . It is often very difficult to unit test code that wasn’t built with testing in mind. Sprout involves creating the new functionality elsewhere, testing it and adding it to a legacy method known as the insertion point. Another technique is to wrap the existing functionality by creating a new method