重構(gòu)

出版時間:20101028  出版社:人民郵電出版社  作者:Martin Fowler  頁數(shù):431  
Tag標簽:無  

前言

"重構(gòu)"這個概念來自Smalltalk圈子,沒多久就進入了其他語言陣營之中。由于重構(gòu)是框架開發(fā)中不可缺少的一部分,所以當框架開發(fā)人員討論自己的工作時,這個術(shù)語就誕生了。當他們精練自己的類繼承體系時,當他們叫喊自己可以拿掉多少多少行代碼時,重構(gòu)的概念慢慢浮出水面。框架設(shè)計者知道,這東西不可能一開始就完全正確,它將隨著設(shè)計者的經(jīng)驗成長而進化;他們也知道,代碼被閱讀和被修改的次數(shù)遠遠多于它被編寫的次數(shù)。保持代碼易讀、易修改的關(guān)鍵,就是重構(gòu)——對框架而言如此,對一般軟件也如此。好極了,還有什么問題嗎?問題很顯然:重構(gòu)具有風險。它必須修改運作中的程序,這可能引入一些不易察覺的錯誤。如果重構(gòu)方式不恰當,可能毀掉你數(shù)天甚至數(shù)星期的成果。如果重構(gòu)時不做好準備,不遵守規(guī)則,風險就更大。你挖掘自己的代碼,很快發(fā)現(xiàn)了一些值得修改的地方,于是你挖得更深。挖得愈深,找到的重構(gòu)機會就越多,于是你的修改也愈多……最后你給自己挖了個大坑,卻爬不出去了。為了避免自掘墳?zāi)?,重?gòu)必須系統(tǒng)化進行。我在《設(shè)計模式》書中和另外三位作者曾經(jīng)提過:設(shè)計模式為重構(gòu)提供了目標。然而"確定目標"只是問題的一部分而已,改造程序以達到目標,是另一個難題。

內(nèi)容概要

  《重構(gòu):改善既有代碼的設(shè)計(英文版)》清晰揭示了重構(gòu)的過程,解釋了重構(gòu)的原理和最佳實踐方式,并給出了何時以及何地應(yīng)該開始挖掘代碼以求改善。書中給出了70多個可行的重構(gòu),每個重構(gòu)都介紹了一種經(jīng)過驗證的代碼變換手法的動機和技術(shù)。《重構(gòu):改善既有代碼的設(shè)計(英文版)》提出的重構(gòu)準則將幫助你一次一小步地修改你的代碼,從而減少了開發(fā)過程中的風險。

作者簡介

作者:(美國)福勒(Martin Fowler)Martin Fowler世界軟件開發(fā)大師,在面向?qū)ο蠓治鲈O(shè)計、UML、模式、xP和重構(gòu)等領(lǐng)域都有卓越貢獻?,F(xiàn)為著名軟件開發(fā)咨詢公司Thoughtworks的首席科學家。他的多部著作《分析模式》、《UML精粹》和《企業(yè)應(yīng)用架構(gòu)模式》等都已經(jīng)成為膾炙人口的經(jīng)典。其他參編者Kent Beck軟件開發(fā)方法學的泰斗,極限編程的創(chuàng)始人。他是Three Rivers lnslitule公司總裁,也是Agitar S0ftware的成員。John Brant和Don Roberts The Refactory公司的創(chuàng)始人。Refactory Browser的開發(fā)者。多年來一直從事研究重構(gòu)的實踐與理論。William Opdyke  目前在朗訊貝爾實驗室工作,他寫的關(guān)于面向?qū)ο罂蚣艿牟┦空撐氖侵貥?gòu)方面的第一篇著名文章。

書籍目錄

Chapter 1: Refactoring, a First Example  1The Starting Point 1The First Step in Refactoring 7Decomposing and Redistributing the Statement Method 8Replacing the Conditional Logic on Price Code with Polymorphism 34Final Thoughts 52Chapter 2: Principles in Refactoring 53Defining Refactoring 53Why Should You Refactor 55When Should You Refactor 57What Do I Tell My Manager 60Problems with Refactoring 62Refactoring and Design 66Refactoring and Performance 69Where Did Refactoring Come From 71Chapter 3: Bad Smells in Code (by Kent Beck and Martin Fowler) 75Duplicated Code 76Long Method 76Large Class 78Long Parameter List 78Divergent Change 79Shotgun Surgery 80Feature Envy 80Data Clumps 81Primitive Obsession 81Switch Statements 82Parallel Inheritance Hierarchies 83Lazy Class 83Speculative Generality 83Temporary Field 84Message Chains 84Middle Man 85Inappropriate Intimacy 85Alternative Classes with Different Interfaces 85Incomplete Library Class 86Data Class 86Refused Bequest 87Comments 87Chapter 4: Building Tests 89The Value of Self-testing Code 89The JUnit Testing Framework 91Adding More Tests 97Chapter 5: Toward a Catalog of Refactorings 103Format of the Refactorings 103Finding References 105How Mature Are These Refactorings 106Chapter 6: Composing Methods 109Extract Method 110Inline Method 117Inline Temp 119Replace Temp with Query 120Introduce Explaining Variable 124Split Temporary Variable 128Remove Assignments to Parameters 131Replace Method with Method Object 135Substitute Algorithm 139Chapter 7: Moving Features Between Objects 141Move Method 142Move Field 146Extract Class 149Inline Class 154Hide Delegate 157Remove Middle Man 160Introduce Foreign Method 162Introduce Local Extension 164Chapter 8: Organizing Data 169Self Encapsulate Field 171Replace Data Value with Object 175Change Value to Reference 179Change Reference to Value 183Replace Array with Object 186Duplicate Observed Data 189Change Unidirectional Association to Bidirectional 197Change Bidirectional Association to Unidirectional 200Replace Magic Number with Symbolic Constant 204Encapsulate Field 206Encapsulate Collection 208Replace Record with Data Class 217Replace Type Code with Class 218Replace Type Code with Subclasses 223Replace Type Code with State/Strategy 227Replace Subclass with Fields 232Chapter 9: Simplifying Conditional Expressions 237Decompose Conditional 238Consolidate Conditional Expression 240Consolidate Duplicate Conditional Fragments 243Remove Control Flag 245Replace Nested Conditional with Guard Clauses 250Replace Conditional with Polymorphism 255Introduce Null Object 260Introduce Assertion 267Chapter 10: Making Method Calls Simpler 271Rename Method 273Add Parameter 275Remove Parameter 277Separate Query from Modifier 279Parameterize Method 283Replace Parameter with Explicit Methods 285Preserve Whole Object 288Replace Parameter with Method 292Introduce Parameter Object 295Remove Setting Method 300Hide Method 303Replace Constructor with Factory Method 304Encapsulate Downcast 308Replace Error Code with Exception 310Replace Exception with Test 315Chapter 11: Dealing with Generalization 319Pull Up Field 320Pull Up Method 322Pull Up Constructor Body 325Push Down Method 328Push Down Field 329Extract Subclass 330Extract Superclass 336Extract Interface 341Collapse Hierarchy 344Form Template Method 345Replace Inheritance with Delegation 352Replace Delegation with Inheritance 355Chapter 12: Big Refactorings (by Kent Beck and Martin Fowler) 359Tease Apart Inheritance 362Convert Procedural Design to Objects 368Separate Domain from Presentation 370Extract Hierarchy 375Chapter 13: Refactoring, Reuse, and Reality (by William Opdyke) 379A Reality Check 380Why Are Developers Reluctant to Refactor Their Programs 381A Reality Check (Revisited) 394Resources and References for Refactoring 394Implications Regarding Software Reuse and Technology Transfer 395A Final Note 397References 397Chapter 14: Refactoring Tools (by Don Roberts and John Brant) 401Refactoring with a Tool 401Technical Criteria for a Refactoring Tool 403Practical Criteria for a Refactoring Tool 405Wrap Up 407Chapter 15: Putting It All Together (by Kent Beck) 409References 413List of Soundbites 417Index 419

章節(jié)摘錄

插圖:Any technical author has the problem of deciding when to publish. The earlieryou publish, the quicker people can take advantage of the ideas. However, people are always learning. If you publish half-baked ideas too early, the ideas canbe incomplete and even lead to problems for those who try to use them.   The basic technique of refactoring, taking small steps and testing often, hasbeen well tested over many years, especially in the Smalltalk community. So I'mconfident that the basic idea of refactoring is very stable.   The refactorings in this book are my notes about the refactorings I use. Ihave used them all. However, there is a difference between using a refactoringand boiling it down into the mechanical steps I give herein. In particular, youoccasionally see problems that crop up only in very specific circumstances. Icannot say that I have had a lot of people work from these steps to spot many of these kinds of problems. As you use the refactorings, be aware of what youare doing. Remember that like working with a recipe, you have to adapt the refactorings to your circumstances. If you run into an interesting problem, dropme an e-mail, and I'll try to pass on these circumstances for others.

編輯推薦

《重構(gòu):改善既有代碼的設(shè)計(英文版)》:軟件開發(fā)的不朽經(jīng)典、生動闡述重構(gòu)原理和具體做法、普通程序員進階到編程高手必須修煉的秘笈。

圖書封面

圖書標簽Tags

評論、評分、閱讀與下載


    重構(gòu) PDF格式下載


用戶評論 (總計12條)

 
 

  •   經(jīng)典著作,不適合學生或沒有開發(fā)經(jīng)驗的人,有一定開發(fā)經(jīng)驗的人一定好好看看,真心挺好
  •   序言沒有英文原文,只有中文譯文。
  •   物流快,書面有折痕,不影響閱讀
  •   一直在重構(gòu)自己的代碼,也總結(jié)出很多方案, 看了福勒 才知道什么是集大成者
  •   印象比較深的是:當對代碼做修改感到困難時, 這時候需要重構(gòu)
  •   發(fā)貨很快,隔天收到。內(nèi)容自不必我說。可是書體有些折損,被折磨得像一本老書一樣,可憐呀!不知道是不是運送過程中出現(xiàn)的問題,不過紙張和印刷字體很贊!能不能保證運送的質(zhì)量呀?每次收到的書都會多少被弄壞!
  •   前幾頁是中文,感覺怪怪的,不過總體來說,還是不錯!本人認為這本書是很值得去細看,去思考的。
  •   書的內(nèi)容不錯,除了有點坑,在描述上的需要,會比較重復(fù)的打印一頁頁代碼。在設(shè)計模式熟悉了后,結(jié)合工作經(jīng)驗會有不同的領(lǐng)會。
  •   前段時間因為公司需要code refactorying,于是購買了此書,讀后很有收獲。有些思想在我們項目重構(gòu)中也用到。個人認為:這是不僅是一本技術(shù)書,更是一本編程思想書。找時間還是要細細品味一下,學以致用,哈哈
  •   一直都很追求代碼的優(yōu)雅性,也在實踐中用了一些重構(gòu)的方法,看到這本書,算是為實踐找到了理論依據(jù),很好!例子明白、有針對性,英文用詞易懂、不生僻!
  •   書,現(xiàn)在我只看了前面一部分,但我感覺我看的很爽,尤其是Martin Folwer,他寫的東西,我看起來不會頭疼(英文書中),有些英文書看起來很晦澀,而他的我就感覺很流暢。還有就是這真是一本很不錯的書。
  •   很好 質(zhì)量還不錯
 

250萬本中文圖書簡介、評論、評分,PDF格式免費下載。 第一圖書網(wǎng) 手機版

京ICP備13047387號-7