没有合适的资源?快使用搜索试试~ 我知道了~
首页31天代码重构速成 你必须知道的重构技巧
31天代码重构速成 你必须知道的重构技巧
需积分: 15 26 下载量 119 浏览量
更新于2023-07-11
1
收藏 368KB PDF 举报
简介 重构是持续改进代码的基础。抵制重构将带来技术麻烦:忘记代码片段的功能、创建无法测试的代码等等。 而有了重构,使用单元测试、共享代码以及更可靠的无bug 的代码这些最佳实践就显得简单多了。 鉴于重构的重要性,我决定在整个8 月份每天介绍一个重构。在开始之前,请允许我事先声明,尽管我试 着对每个重构进行额外的描述和讨论,但我并不是在声明它们的所有权。 我介绍的大多数重构都可以在Refactoring.com 中找到,有一些来自《代码大全(第2 版)》,剩下的则是我 自己经常使用或从其他网站找到的。我觉得注明每个重构的出处并不是重要的,因为你可以在网上不同的 帖子或文章中找到名称类似的重构。 本着这一精神,我将在明天发布第一篇帖子并开始长达31天的重构马拉松之旅。希望你们能够享受重构并 从中获益。
资源详情
资源推荐
![](https://csdnimg.cn/release/download_crawler_static/2156663/bg1.jpg)
31 天重构速成
你必须知道的重构技巧
2009-11-01
Sean Chambers, Simone Chiaretta
麒麟.NET 译
![](https://csdnimg.cn/release/download_crawler_static/2156663/bg3.jpg)
目录
简介 .............................................................................................................................................................. 5
Refactoring Day 1 : Encapsulate Collection ..................................................................................................... 6
Refactoring Day 2 : Move Method .................................................................................................................. 7
Refactoring Day 3 : Pull Up Method ............................................................................................................. 10
Refactoring Day 4 : Push Down Method ....................................................................................................... 12
Refactoring Day 5 : Pull Up Field................................................................................................................... 13
Refactoring Day 6 : Push Down Field ............................................................................................................ 14
Refactoring Day 7 : Rename(method,class,parameter) ................................................................................. 15
Refactoring Day 8 : Replace Inheritance with Delegation .............................................................................. 16
Refactoring Day 9 : Extract Interface ............................................................................................................ 18
Refactoring Day 10 : Extract Method ............................................................................................................ 20
Refactoring Day 11 : Switch to Strategy ........................................................................................................ 22
Refactoring Day 12 : Break Dependencies .................................................................................................... 27
Refactoring Day 13 : Extract Method Object ................................................................................................. 29
Refactoring Day 14 : Break Responsibilities .................................................................................................. 32
Refactoring Day 15 : Remove Duplication ..................................................................................................... 34
Refactoring Day 16 : Encapsulate Conditional............................................................................................... 36
Refactoring Day 17 : Extract Superclass ........................................................................................................ 37
Refactoring Day 18 : Replace exception with conditional .............................................................................. 38
Refactoring Day 19 : Extract Factory Class .................................................................................................... 40
Refactoring Day 20 : Extract Subclass ........................................................................................................... 42
Refactoring Day 21 : Collapse Hierarchy ....................................................................................................... 43
Refactoring Day 22 : Break Method .............................................................................................................. 44
Refactoring Day 23 : Introduce Parameter Object ........................................................................................ 47
Refactoring Day 24 : Remove Arrowhead Antipattern .................................................................................. 48
Refactoring Day 25 : Introduce Design By Contract checks ........................................................................... 50
Refactoring Day 26 : Remove Double Negative ............................................................................................. 52
Refactoring Day 27 : Remove God Classes .................................................................................................... 54
Refactoring Day 28 : Rename boolean method............................................................................................. 56
![](https://csdnimg.cn/release/download_crawler_static/2156663/bg4.jpg)
Refactoring Day 29 : Remove Middle Man ................................................................................................... 57
Refactoring Day 30 : Return ASAP ................................................................................................................ 59
Refactoring Day 31 : Replace conditional with Polymorphism ...................................................................... 61
附录 A ......................................................................................................................................................... 63
![](https://csdnimg.cn/release/download_crawler_static/2156663/bg5.jpg)
简介
重构是持续改进代码的基础。抵制重构将带来技术麻烦:忘记代码片段的功能、创建无法测试的代码等等。
而有了重构,使用单元测试、共享代码以及更可靠的无 bug 的代码这些最佳实践就显得简单多了。
鉴于重构的重要性,我决定在整个 8 月份每天介绍一个重构。在开始之前,请允许我事先声明,尽管我试
着对每个重构进行额外的描述和讨论,但我并不是在声明它们的所有权。
我介绍的大多数重构都可以在 Refactoring.com 中找到,有一些来自《代码大全(第 2 版)》,剩下的则是我
自己经常使用或从其他网站找到的。我觉得注明每个重构的出处并不是重要的,因为你可以在网上不同的
帖子或文章中找到名称类似的重构。
本着这一精神,我将在明天发布第一篇帖子并开始长达 31 天的重构马拉松之旅。希望你们能够享受重构并
从中获益。
剩余62页未读,继续阅读
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://profile-avatar.csdnimg.cn/default.jpg!1)
zjjmsjsy
- 粉丝: 2
- 资源: 3
上传资源 快速赚钱
我的内容管理 收起
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![](https://csdnimg.cn/release/wenkucmsfe/public/img/voice.245cc511.png)
会员权益专享
最新资源
- 保险服务门店新年工作计划PPT.pptx
- 车辆安全工作计划PPT.pptx
- ipqc工作总结PPT.pptx
- 车间员工上半年工作总结PPT.pptx
- 保险公司员工的工作总结PPT.pptx
- 报价工作总结PPT.pptx
- 冲压车间实习工作总结PPT.pptx
- ktv周工作总结PPT.pptx
- 保育院总务工作计划PPT.pptx
- xx年度现代教育技术工作总结PPT.pptx
- 出纳的年终总结PPT.pptx
- 贝贝班班级工作计划PPT.pptx
- 变电值班员技术个人工作总结PPT.pptx
- 大学生读书活动策划书PPT.pptx
- 财务出纳月工作总结PPT.pptx
- 大学生“三支一扶”服务期满工作总结(2)PPT.pptx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
![](https://img-home.csdnimg.cn/images/20220527035711.png)
![](https://img-home.csdnimg.cn/images/20220527035711.png)
![](https://img-home.csdnimg.cn/images/20220527035111.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![](https://csdnimg.cn/release/wenkucmsfe/public/img/green-success.6a4acb44.png)