重構:改善既有代碼的設計(英文注釋版)

重構:改善既有代碼的設計(英文注釋版)
定價:414
NT $ 360
 

內容簡介

本書清晰地揭示了重構的過程,解釋了重構的原理和最佳實踐方式,並給出了何時以及何地應該開始挖掘代碼以求改善。

書中給出了70多個可行的重構,每個重構都介紹了一種經過驗證的代碼變換手法的動機和技術。本書提出的重構准則將幫助你一次一小步地修改你的代碼,從而減少了開發過程中的風險。

  本書適合軟件開發人員、項目管理人員等閱讀,也可作為高等院校計算機及相關專業師生的參考讀物。
 

目錄

Chapter 1:Refactoring,a First Example 重構,第一個例子 
 The Starting Point 起點 
 The First Step in Refactoring 重構第一步 
 Decomposing and Redistributing the Statement Method 分解並重組slalemenl方法 
 Replacing the Conditional Logic on Price Code with Polymorphism 用多態代替價格條件邏輯代碼 
 Final Thoughts 結語 
Chapter 2:Principles in Refactoring 重構原則 
 Defining Refactoring 何謂重構 
 Why Should You Refactor? 為何重構 
 When Should You Refactor? 何時重構 
 What Do I Tell My Manager? 怎樣說服經理 
 Problems with Refactoring 重構的問題 
 Refactoring and Design 重構與設計 
 Refactoring and Performance 重構與性能 
 Where Did Refactoring Come From? 重構的起源 
Chapter 3:Bad Smells in Code(by Kent Beck and Martin Fowler) 代碼壞昧 
 Duplicated Code 重復代碼 
 Long Method 過長方法 
 Large Class 過長類 
 Long Parameter List 過長參數列表 
 Divergent Change 發散式變化 
 Shotgun Surgery 霰彈式修改 
 Feature Envy 特性依戀 
 Data Clumps 數據泥團 
 Primitive Obsession 基本類型偏執 
 Switch Statements switch語句 
 Parallel Inheritance Hierarchies 平行繼承體系 
 Lazy Class 冗余類 
 Speculative Generality 理論上的一般性 
 Temporary Field 臨時字段 
 Message Chains 消息鏈 
 Middle Man 中間人 
 Inappropriate Intimacy 過度親密 
 Alternative Classes with Different Interfaces 接口不同的等效類
 Incomplete Library Class 不完整的庫類 
 Data Class 數據類 
 Refused Bequest 拒絕繼承 
 Comments 注釋過多 
Chapter 4:Building Tests 構建測試 
 The Value of Self-testing Code 自測試代碼的重要性 
 The JUnit Testing Framework Junit測試框架 
 Adding More Tests 添加更多測試 
Chapter 5:Toward a Catalog of Refactorings 重構目錄 
 Format of the Refactorings 重構描述的格式 
 Finding References 尋找引用 
 How Mature Are These Refactorings? 這些重構的成熟度如何
Chapter 6:Composing Methods 組合方法 
 Extract Method 提取方法 
 Inline Method 內聯方法 
 Inline Temp 內聯臨時變量 
 *Replace Temp with Query 用查詢方法代替臨時變量 
 Introduce Explaining Variable 引入解釋性變量 
 Split Temporary Variable 分離臨時變量 
 *Remove Assignments to Parameters 去除參數賦值 
 Replace Method with Method Object 用方法對象代替方法 
 Substitute Algorithm 替換算法 
Chapter 7:Moving Features Between Objects 在對象之間移動特性
 *Move Method 移動方法 
 Move Field 移動字段 
 Extract Class 提取類 
 Inline Class 內聯類 
 Hide Delegate 隱藏委托類 
 Remove Middle Man 去除中間人 
 Introduce Foreign Method 引入外加方法 
 *Introduce Local Extension 引入本地擴展類 
Chapter 8:Organizing Data 組織數據 
 Self Encapsulate Field 自封裝字段 
 Replace Data Value with Object 用對象代替數據值 
 Change Value to Reference 將值對象改為引用對象 
 Change Reference to Value 將引用對象改為值對象 
 Replace Array with Object 用對象代替數組 
 Duplicate Observed Data 重復被觀察數據 
 *Change Unidirectional Associationto Bidirectional 將單向關聯改為雙向 
 Change Bidirectional Association to Unidirectional 將雙向關聯改為單向 
 *Replace Magic Number with Symbolic Constant 用字面常量代替魔數 
 Encapsulate Field 封裝字段 
 Encapsulate Collection 封裝集合 
 Replace Record with Data Class 用數據類代替記錄 
 *ReplaceType Code with Class 用類代替類型碼 
 Replace Type Code with Subclasses 用子類代替類型碼 
 Replace Type Code with State/Strategy用State/Strategy 代替類型碼 
 Replace Subclass with Fields 用字段代替子類 
Chapter 9:Simplifying Conditional Expressions 簡化條件語句 
 Decompose Conditional 分解條件語句 
 Consolidate Conditional Expression 合並條件語句 
 Consolidate Duplicate Conditional Fragments 合並重復的條件片段 
 Remove Control Flag 去除控制標志 
 Replace Nested Conditional with Guard Clauses 用守衛語句代替嵌套條件語句 
 Replace Conditional with Polymorphism 用多態代替條件語句  Introduce Null Object 引入Null對象 
 Introduce Assertion 引入斷言 
Chapter 10:Making Method Calls Simpler 簡化方法調用 
 Rename Method 重命名方法 
 Add Parameter 添加參數 
 Remove Parameter 去除參數 
 Separate query from Modifier 將查詢方法與修改方法分離
 Parameterize Method 參數化方法
 Replace Parameter with Explicit Methods 用顯式方法代替參數
 Preserve Whole Object 保持對象完整
 Replace Parameter with Method 用方法代替參數 
 Introduce Parameter Object 引入參數對象
 Remove Setting Method 去除設置方法 
 Hide Method 隱藏方法 
 Replace Constructor with Factory Method 用工廠方法代替構造器
 Encapsulate Downcast 封裝向下轉型 
 Replace Error Code with Exception 用異常代替錯誤碼 
 Replace Exception with Test 用測試代替異常
Chapter 11:Dealing with Generalization 處理泛化關系 
 Pull Up Field 上移字段 
 Pull UP Method 上移方法 
 Pull Up Constructor Body 上移構造器主體 
 Push Down Method 下移方法
 Push Down Field 下移字段 
 Extract Subclass 提取子類 
 Extract Superclass 提取超類
 Extract Interface 提取接口
 Collapse Hierarchy 合並繼承層次 
 Form Template Method 形成Template Method 
 Replace Inheritance with Delegation 用委托代替繼承 
 Replace Delegation with Inheritance 用繼承代替委托5
Chapter 12:Big Refactorings(by Kent Beck and Martin Fowler) 大型重構 
 Tease Apart Inheritance 分解繼承層次 
 Convert Procedural Design to Objects 將過程式設計轉換為面向對象 
 Separate Domain from Presentation 將領域邏輯與表現分離
 Extract Hierarchy 提取繼承層次
Chapter 13:Refactoring,Reuse,and Reality(by William Opdyke) 重構,復用與現實
 A Reality Check 現實的檢驗
 Whv Are Developers Reluctant to Refactor Their Programs? 開發人員為何不願重構程序
 A Reality Check(Revisited) 再談現實的檢驗
 Resources and References for Refactoring 重構的資源和參考文獻 
 Implications Regarding Software Reuse and Technology Transfer 對軟件復用與技術傳播的意義 
 A Final Note 結語 
 References 參考文獻 
Chapter 14:Refactoring Tools(by Don Roberts and John Brant) 重構工具 
 Refactoring with a Tool 使用工具重構
 Technical Criteria for a Refactoring Tool 重構工具的技術標准 
 Practical Criteria for a Refactoring Tool 重構工具的實用標准
 Wrap Up 結語 
Chapter 15:Putting It All Together(by Kent Beck) 集大成 
References參考文獻 
List of Soundbites 要點列表
Updates 更新內容 
Index 索引
 

重構(refactoring)的概念出自Smalltalk界,但很快就進入了其他語言陣營。重構在框架開發中不可或缺,所以這個術語是框架開發人員在討論自己的技藝時油然而生的。當他們改善自己的類層次結構時,當他們熱烈討論又可以刪去多少行代碼時,重構的概念就產生了。設計者知道,框架不可能第一次就完美無缺,它必須隨着設計者的經驗增長而改進;設計者也知道,閱讀和修改代碼的次數遠遠多於編寫代碼。要使代碼易讀、易修改,秘決就在於重構——對框架而言如此,對一般軟件也如此。

那麼,重構有什麼問題嗎?簡而言之,重構是有風險的。它要修改的是可以工作的程序,這可能引入一些微妙的錯誤。如果重構不當,可能使數天乃至數星期的工作前功盡棄。如果重構時有章不循、草率為之,風險將更大。開始深入自己的代碼時,很快就會發現一些需要修改的地方,於是你更加深入。探究越深,找到的重構機會就越多……於是修改也越多。最后你挖了一個大坑,自己卻爬不出去了。為了避免自掘墳墓,重構必須按部就班地進行。我和合著者寫《設計模式》一書時曾提到:設計模式為重構提供了目標。然而「確定目標」只是問題之一,轉換程序達到目標,是另一個難題。

Martin Fowler和本書另幾位作者清楚闡述了重構過程,他們為面向對象軟件開發做出了重大貢獻。本書解釋了重構的原理和最佳實踐,並指出在什麼場合應該開始深入研究代碼,進行改進。本書的核心部分是一個完整的重構目錄,其中每一個重構都介紹了一種經過驗證的代碼轉換的動機和做法。某些重構,如Extract Method和Move Field乍看起來顯而易見,但切不可掉以輕心,因為理解這種重構的做法正是有條不紊地進行重構的關鍵。本書中的重構將幫助你每次一小步地修改代碼,從而減少了設計修改過程中的風險。很快,這些重構的名字就會成為你日常的開發詞匯。

我第一次體驗嚴格的、每次一小步的重構,是在30 000英尺高空與Kent Beck進行結對編程(palr-programmlng)』c我們應用本書中的重構,每次只走一步。最后,我對這種實踐方式的效果感到十分驚訝。我不但對最后結果更有信心,而且感到開發時自己的壓力也小了很多。所以,我強烈推薦你嘗試這些重構,你的生活和你的程序都將因此更美好。
網路書店 類別 折扣 價格
  1. 新書
    87
    $360