Martin Fowler,世界软件开发大师,在面向对象分析设计、UML、模式、XP和重构等领域都有卓越贡献,现为软件开发咨询公司ThoughtWorks的首席科学家。他的多部著作《分析模式》、《UML精粹》和《企业应用架构模式》等都已经成为脍炙人口的经典。
目录
第1章重构,第一个案例 1 1.1起点 1 1.2重构的第一步 7 1.3分解并重组statement() 8 1.4运用多态取代与价格相关的条件逻辑 34 1.5结语 52 第2章重构原则 53 2.1何谓重构 53 2.2为何重构 55 2.3何时重构 57 2.4怎么对经理说 60 2.5重构的难题 62 2.6重构与设计 66 2.7重构与性能 69 2.8重构起源何处 71 第3章代码的坏味道 75 3.1Duplicated Code(重复代码) 76 3.2Long Method(过长函数) 76 3.3Large Class(过大的类) 78 3.4Long Parameter List(过长参数列) 78 3.5Divergent Change(发散式变化) 79 3.6Shotgun Surgery(霰弹式修改) 80 3.7Feature Envy(依恋情结) 80 3.8Data Clumps(数据泥团) 81 3.9Primitive Obsession(基本类型偏执) 81 3.10Switch Statements(switch惊悚现身) 82 3.11Parallel InheritanceHierarchies(平行继承体系) 83 3.12Lazy Class(冗赘类) 83 3.13Speculative Generality(夸夸其谈未来性) 83 3.14Temporary Field(令人迷惑的暂时字段) 84 3.15Message Chains(过度耦合的消息链) 84 3.16Middle Man(中间人) 85 3.17Inappropriate Intimacy(狎昵关系) 85 3.18Alternative Classes with Different Interfaces(异曲同工的类) 85 3.19Incomplete Library Class(不完美的库类) 86 3.20Data Class(纯稚的数据类) 86 3.21Refused Bequest(被拒绝的遗赠) 87 3.22Comments(过多的注释) 87 第4章构筑测试体系 89 4.1自测试代码的价值 89 4.2JUnit测试框架 91 4.3添加更多测试 97 第5章重构列表 103 5.1重构的记录格式 103 5.2寻找引用点 105 5.3这些重构手法有多成熟 106 第6章重新组织函数 109 6.1Extract Method(提炼函数) 110 6.2Inline Method(内联函数) 117 6.3Inline Temp(内联临时变量) 119 6.4Replace Temp with Query(以查询取代临时变量) 120 6.5Introduce Explaining Variable(引入解释性变量) 124 6.6Split Temporary Variable(分解临时变量) 128 6.7Remove Assignments to Parameters(移除对参数的赋值) 131 6.8Replace Method with Method Object(以函数对象取代函数) 135 6.9Substitute Algorithm(替换算法) 139 第7章在对象之间搬移特性 141 7.1Move Method(搬移函数) 142 7.2Move Field(搬移字段) 146 7.3Extract Class(提炼类) 149 7.4Inline Class(将类内联化) 154 7.5Hide Delegate(隐藏“委托关系”) 157 7.6Remove Middle Man(移除中间人) 160 7.7Introduce Foreign Method(引入外加函数) 162 7.8Introduce Local Extension(引入本地扩展) 164 第8章重新组织数据 169 8.1Self Encapsulate Field(自封装字段) 171 8.2Replace Data Value with Object(以对象取代数据值) 175 8.3Change Value to Reference(将值对象改为引用对象) 179 8.4Change Reference to Value(将引用对象改为值对象) 183 8.5Replace Array with Object(以对象取代数组) 186 8.6Duplicate Observed Data(复制“被监视数据”) 189 8.7Change Unidirectional Association to Bidirectional(将单向关联改为双向关联) 197 8.8Change Bidirectional Association to Unidirectional(将双向关联改为单向关联) 200 8.9Replace Magic Number with Symbolic Constant(以字面常量取代魔法数) 204 8.10Encapsulate Field(封装字段) 206 8.11Encapsulate Collection(封装集合) 208 8.12Replace Record with Data Class(以数据类取代记录) 217 8.13Replace Type Code with Class(以类取代类型码) 218 8.14Replace Type Code with Subclasses(以子类取代类型码) 223 8.15Replace Type Code with State/Strategy(以State/Strategy取代类型码) 227 8.16Replace Subclass with Fields(以字段取代子类) 232 第9章简化条件表达式 237 9.1Decompose Conditional(分解条件表达式) 238 9.2Consolidate Conditional Expression(合并条件表达式) 240 9.3Consolidate Duplicate Conditional Fragments(合并重复的条件片段) 243 9.4Remove Control Flag(移除控制标记) 245 9.5Replace Nested Conditional with Guard Clauses(以卫语句取代嵌套条件表达式) 250 9.6Replace Conditional with Polymorphism(以多态取代条件表达式) 255 9.7Introduce Null Object(引入Null对象) 260 9.8Introduce Assertion(引入断言) 267 第10章简化函数调用 271 10.1Rename Method(函数改名) 273 10.2Add Parameter(添加参数) 275 10.3Remove Parameter(移除参数) 277 10.4Separate Query from Modifier(将查询函数和修改函数分离) 279 10.5Parameterize Method(令函数携带参数) 283 10.6Replace Parameter with Explicit Methods(以明确函数取代参数) 285 10.7Preserve Whole Object(保持对象完整) 288 10.8Replace Parameter with Methods(以函数取代参数) 292 10.9Introduce Parameter Object(引入参数对象) 295 10.10Remove Setting Method(移除设值函数) 300 10.11Hide Method(隐藏函数) 303 10.12Replace Constructor with Factory Method(以工厂函数取代构造函数) 304 10.13Encapsulate Downcast(封装向下转型) 308 10.14Replace Error Code with Exception(以异常取代错误码) 310 10.15Replace Exception with Test(以测试取代异常) 315 第11章处理概括关系 319 11.1Pull Up Field(字段上移) 320 11.2Pull Up Method(函数上移) 322 11.3Pull Up Constructor Body(构造函数本体上移) 325 11.4Push Down Method(函数下移) 328 11.5Push Down Field(字段下移) 329 11.6Extract Subclass(提炼子类) 330 11.7Extract Superclass(提炼超类) 336 11.8Extract Interface(提炼接口) 341 11.9Collapse Hierarchy(折叠继承体系) 344 11.10Form Tem Plate Method(塑造模板函数) 345 11.11Replace Inheritance with Delegation(以委托取代继承) 352 11.12Replace Delegation with Inheritance(以继承取代委托) 355 第12章大型重构 359 12.1Tease Apart Inheritance(梳理并分解继承体系) 362 12.2Convert Procedural Design to Objects(将过程化设计转化为对象设计) 368 12.3Separate Domain from Presentation(将领域和表述/显示分离) 370 12.4Extract Hierarchy(提炼继承体系) 375 第13章重构,复用与现实 379 13.1现实的检验 380 13.2为什么开发者不愿意重构他们的程序 381 13.3再论现实的检验 394 13.4重构的资源和参考资料 394 13.5从重构联想到软件复用和技术传播 395 13.6小结 397 13.7参考文献 397 第14章重构工具 401 14.1使用工具进行重构 401 14.2重构工具的技术标准 403 14.3重构工具的实用标准 405 14.4小结 407 第15章总结 409 参考书目 413 要点列表 417 索引 419
精彩书摘
《重构 改善既有代码的设计 英文版》: Now it was easy to run a test—as easy as compiling.So I started to run tests every time I compiled.Soon I began to notice my productivity had shot upward.1 realized that I wasn't spending so much time debugging.If I added a bug that was caught by a previous test, it would show up as soon as I ran that test.Because the test had worked before, I would know that the bug was in the work I had done since I last tested.Because I ran the tests frequently, only a few minutes had elapsed.I thus knew that the source of the bug was the code I had just written, Because that code was fresh in my mind and was a small amount, the bug was easy to find.Bugs that once had taken an hour or more to find now took a couple of minutes at most.Not just had I built self—testing classes, but by running them frequently I had a powerful bug detector. As I noticed this I became more aggressive about doing the tests.Instead of waiting for the end of increment, I would add the tests immediately after writing a bit of function.Every day I would add a couple of new features and the tests to test them.These days I hardly ever spend more than a few minutes debugging. ……
评论{{'('+ commentList.posts_count + ')'}}
分享你的感受,帮助更多用户做出选择。
写评论{{ showTranslate(comment) }}收起
{{ strLimit(comment,800) }}查看全部
Show Original{{ comment.content }}
{{ formatTime(comment.in_dtm) }} 已购买 {{groupData}}
{{ showTranslate(comment) }}收起
{{ strLimit(comment,800) }}查看全部
Show Original{{ comment.content }}
{{ formatTime(comment.in_dtm) }} 已购买 {{groupData}}
暂无符合条件的评论
评论详情
{{commentDetails.user_name}}
{{ showTranslate(commentDetails) }}收起
{{ strLimit(commentDetails,800) }}查看全部
Show Original{{ commentDetails.content }}
{{ formatTime(commentDetails.in_dtm) }} 已购买 {{groupData}}
回复{{'(' + replyList.length + ')'}}
{{ confirmUser(reply) }}回复{{ reply.parent_user_name }}
{{ showTranslate(reply) }}收起
{{ strLimit(reply,800) }}查看全部
Show Original{{ reply.reply_content }}
{{ formatTime(reply.reply_in_dtm) }}
End
请输入评论
举报
确认删除该评论吗?
取消