【重构】二、重构列表和重构方法速查表

【重构】二、重构列表和重构方法速查表


重构和设计模式在线快查:Design Patterns & Refactoring

坏味道

分类Bad code smells

Bloaters

Bloaters are code, methods and classes that have increased to such gargantuan proportions that they are hard to work with.

Usually these smells do not crop up right away, rather they accumulate over time as the program evolves (and especially when nobody makes an effort to eradicate them).

Long Method

过长方法

Long Parameter List

过长参数列表

Large Class

过大类

Data Clumps

数据泥团

Primitive Obsession

基本类型偏执

Object-Orientation Abusers

All these smells are incomplete or incorrect application of object-oriented programming principles.

Switch Statements

switch语句

Refused Bequest

被拒绝的遗赠

Temporary Field

临时字段

Alternative Classes with Different Interfaces

异曲同工的类

Change Preventers

These smells mean that if you need to change something in one place in your code, you have to make many changes in other places too.

Program development becomes much more complicated and expensive as a result.

Divergent Change

发散式变化

Shotgun Surgery

霰弹式修改

Parallel Inheritance Hierarchies

平行继承

Dispensables

A dispensable is something pointless and unneeded whose absence would make the code cleaner, more efficient and easier to understand.

 Comments

注释

 Duplicate Code

重复代码

 Lazy Class

冗余类

 Data Class

纯数据类

Dead Code

死码

Speculative Generality

夸夸其谈未来性

Couplers

All the smells in this group contribute to excessive coupling between classes or show what happens if coupling is replaced by excessive delegation.





Feature Envy

依恋情结

Inappropriate Intimacy

过度亲密

Message Chains

消息链

Middle Man

中间人

Incomplete Library Class

不完整的类库

重构手段

分类Refactoring techniques

Composing methods

Much of refactoring is devoted to correctly composing methods. In most cases, excessively long methods are the root of all evil.

The vagaries of code inside these methods conceal the execution logic and make the method extremely hard to understand – and even harder to change.

 

The refactoring techniques in this group streamline methods, remove code duplication, and pave the way for future improvements.

 Extract Method

提炼函数

 Inline Method

内联函数

 Extract Variable

提炼变量

 Inline Temp

内联变量

 Replace Temp with Query

以查询替代临时变量

 Split Temporary Variable

拆分临时变量

 Remove Assignments to Parameters

移除对参数的赋值操作

 Replace Method with Method Object

用方法对象替换方法

Substitute Algorithm

替换算法

Moving Features between Objects

Even if you have distributed functionality among different classes in a less-than-perfect way, there is still hope.

 

These refactoring techniques show how to safely move functionality between classes, create new classes, and hide implementation details from public access.









Move Method

移动方法

Move Field

移动字段

Extract Class

提取类

Inline Class

内联类

Hide Delegate

隐藏委托关系

Remove Middle Man

移除中间人

Introduce Foreign Method

引入外加方法

Introduce Local Extension

引入本地扩展

Organizing Data

These refactoring techniques help with data handling, replacing primitives with rich class functionality.

Another important result is untangling of class associations, which makes classes more portable and reusable.



 

 

 

 

 

 

 

 

 

 

 

 

 

Self Encapsulate Field

自封装字段

Replace Data Value with Object

以对象替换数据值

Change Value to Reference

将值对象改为引用对象

Change Reference to Value

将引用对象改为值对象

Replace Array with Object

用对象替换数组

Duplicate Observed Data

重复被观察数据

Replace Magic Number with Symbolic Constant

用符号常量代替魔法值

Encapsulate Field

封装字段

Encapsulate Collection

封装集合

Replace Type Code with Class

类型代码替换为类

Replace Type Code with Subclasses

类型代码替换为子类

Replace Type Code with State/Strategy

类型代码替换为状态/策略模式

Replace Subclass with Fields

子类替换为字段

Simplifying Conditional Expressions

Conditionals tend to get more and more complicated in their logic over time, and there are yet more techniques to combat this as well.

Decompose Conditional

分解条件表达式

Consolidate Duplicate Conditional Fragments

合并条件中重复的片段

移除控制标志

Replace Nested Conditional with Guard Clauses

以卫语句取代条件表达式

Replace Conditional with Polymorphism

以多态替换条件表达式

Introduce Null Object

引入空对象

Introduce Assertion

引入断言

Simplifying Method Calls

These techniques make method calls simpler and easier to understand. This, in turn, simplifies the interfaces for interaction between classes.

Rename Method

重命名方法

Add Parameter

添加参数

Remove Parameter

移除参数

Separate Query from Modifier

查询和更改分开

Parameterize Method

参数化方法

Replace Parameter with Explicit Methods

以显示方法替换参数

保持对象完整

Replace Parameter with Method Call

以方法调用替换参数

Introduce Parameter Object

引入参数对象

Remove Setting Method

移除设值函数

Hide Method

隐藏方法

Replace Constructor with Factory Method

用工厂方法替换构造方法

Replace Error Code with Exception

用异常替换失败码

Replace Exception with Test

用条件判断替换异常

 

Pull Up Field

字段上移

Pull Up Method

方法上移

Pull Up Constructor Body

构造函数体上移

Push Down Method

方法下移

Push Down Field

字段下移

Extract Subclass

提取子类

提取超类

Extract Interface

提取接口

Collapse Hierarchy

折叠继承关系

Form Template Method

塑造模板方法

Replace Inheritance with Delegation

用委托替代继承

Replace Delegation with Inheritance

用继承替代委托

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章