追求梦想,程序人生。

《重构与模式》代码坏味与重构的方法

代码坏味

重构

重复代码(Duplicated Code

形成Template Method

Factory Method引入多态创建

链构造函数

Composite解决一/多之分

提取Composite

通过Adapter统一接口

引入Null Object

方法过长(Long Method

组合方法

将聚集操作搬移到Collecting Parameter

Command替换条件调度程序

将聚集操作搬移到Visitor

Strategy替换条件逻辑

条件逻辑太复杂(Conditional Complexity

Strategy替换条件逻辑

将装饰功能搬移到Decorator

State替换状态改变条件语句

引入Null Object

基本类型迷恋(Primitive Obsession

用类替换类型代码

State替换状态改变条件语句

Strategy替换条件逻辑

Composite替换隐含树

Interpreter替换隐式语言

将装饰功能搬移到Decorator

Builder封装Composite

不恰当的暴露(Indecent Exposure

Factory封装类

解决方案蔓延(Solution Sprawl

将创建知识搬移到Factory

异曲同工的类(Alternative Classes With Different Interface

通过Adapter统一接口

冗赘类(Lazy Class

内联Singleton

类过大(Large Class

Command替换条件调度程序

State替换状态改变条件语句

Interpreter替换隐式语言

分支语句(Switch Statement

Command替换条件调度程序

将聚集操作搬移到Visitor

组合爆炸(Combinatorial Explosion

Interpreter替换隐式语言

怪异解决方案(Oddball Solution

通过Adapter统一接口

 

posted on 2011-05-23 12:49  伊默宁  阅读(267)  评论(0)    收藏  举报