本節書摘來自異步社群《重構:改善既有代碼的設計》一書中的重構清單,作者【美】martin fowler,更多章節内容可以通路雲栖社群“異步社群”公衆号檢視。
重構清單
重構:改善既有代碼的設計
add parameter(添加參數)
change bidirectional association to unidirectional(将雙向關聯改為單向關聯)
change reference to value(将引用對象改為值對象)
change unidirectional association to bidirectional(将單向關聯改為雙向關聯)
change value to reference(将值對象改為引用對象)
collapse hierarchy(折疊繼承體系)
consolidate conditional expression(合并條件表達式)
consolidate duplicate conditional fragments(合并重複的條件片段)
convert procedural design to objects(将過程化設計轉化為對象設計)
decompose conditional(分解條件表達式)
duplicate observed data(複制“被監視資料”)
encapsulate collection(封裝集合)
encapsulate downcast(封裝向下轉型)
encapsulate field(封裝字段)
extract class(提煉類)
extract hierarchy(提煉繼承體系)
extract interface(提煉接口)
extract method(提煉函數)
extract subclass(提煉子類)
extract superclass(提煉超類)
form template method(塑造模闆函數)
hide delegate(隐藏“委托關系”)
hide method(隐藏函數)
inline class(将類内聯化)
inline method(内聯函數)
inline temp(内聯臨時變量)
introduce assertion(引入斷言)
introduce explaining variable(引入解釋性變量)
introduce foreign method(引入外加函數)
introduce local extension(引入本地擴充)
introduce null object(引入null對象)
introduce parameter object(引入參數對象)
move field(搬移字段)
move method(搬移函數)
parameterize method(令函數攜帶參數)
preserve whole object(保持對象完整)
pull up constructor body(構造函數本體上移)
pull up field(字段上移)
pull up method(函數上移)
push down field(字段下移)
push down method(函數下移)
remove assignments to parameters(移除對參數的指派)
remove control flag(移除控制标記)
remove middle man(移除中間人)
remove parameter(移除參數)
remove setting method(移除設值函數)
rename method(函數改名)
replace array with object(以對象取代數組)
replace conditional with polymorphism(以多态取代條件表達式)
replace constructor with factory method(以工廠函數取代構造函數)
replace data value with object(以對象取代資料值)
replace delegation with inheritance(以繼承取代委托)
replace error code with exception(以異常取代錯誤碼)
replace exception with test(以測試取代異常)
replace inheritance with delegation(以委托取代繼承)
replace magic number with symbolic constant(以字面常量取代魔法數)
replace method with method object(以函數對象取代函數)
replace nested conditional with guard clauses(以衛語句取代嵌套條件表達式)
replace parameter with explicit methods(以明确函數取代參數)
replace parameter with methods(以函數取代參數)
replace record with data class(以資料類取代記錄)
replace subclass with fields(以字段取代子類)
replace temp with query(以查詢取代臨時變量)
replace type code with class(以類取代類型碼)
replace type code with state/strategy(以state/strategy取代類型碼)
replace type code with subclasses(以子類取代類型碼)
self encapsulate field(自封裝字段)
separate domain from presentation(将領域和表述/顯示分離)
separate query from modifier(将查詢函數和修改函數分離)
split temporary variable(分解臨時變量)
substitute algorithm(替換算法)
tease apart inheritance(梳理并分解繼承體系)
本文僅用于學習和交流目的,不代表異步社群觀點。非商業轉載請注明作譯者、出處,并保留本文的原始連結。