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

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


重構和設計模式在線快查: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

用繼承替代委託

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