Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
RefactoringImproving The Design of Existing Code Reporter:Jiayun Zhou <jiayun.zhou@iisigroup.com> Date :2011/07/13
OutlineIntroductionBad Smells & RefactoringsConclusion    Copyright by IISI. All rights reserved   2
Introduction
Eclipse 1.0 – Nov 2001       Copyright by IISI. All rights reserved   4
Eclipse 2.0 – Jun 2002       Copyright by IISI. All rights reserved   5
Eclipse 2.1 – Mar 2003       Copyright by IISI. All rights reserved   6
Eclipse 3.7 – Jun 2011       Copyright by IISI. All rights reserved   7
Copyright by IISI. All rights reserved   8
Martin Fowler   Copyright by IISI. All rights reserved   9
Kent Beck Copyright by IISI. All rights reserved   10
Bad Smells & Refactorings
Bad SmellIf it stinks, change it.                          -Grandma Beck,      discussing child-rearing philosophy        ...
WTFCopyright by IISI. All rights reserved   13
What the Fxxk    Copyright by IISI. All rights reserved   14
Copyright by IISI. All rights reserved   15
Good Programmer• 30% Good Habits• 30% English• 40% Passion, Talent, Practice,  and Everything Else             Copyright b...
Duplicated Code (Bad Smell)           DRY  (Dont Repeat Yourself)          Copyright by IISI. All rights reserved   17
Duplicated Code (Bad Smell)           DRY  (Dont Repeat Yourself)            vs.           WET    (We Enjoy Typing)       ...
Pull Up Method (Refactoring)   Copyright by IISI. All rights reserved   19
Pull Up – 1 (Eclipse)      Copyright by IISI. All rights reserved   20
Pull Up – 2 (Eclipse)      Copyright by IISI. All rights reserved   21
Pull Up – 3 (Eclipse)      Copyright by IISI. All rights reserved   22
Pull Up – 4 (Eclipse)      Copyright by IISI. All rights reserved   23
Pull Up – 5 (Eclipse)      Copyright by IISI. All rights reserved   24
Long Method (Bad Smell)• Short methods are good• Whenever we feel the need to  comment something, we write  a method inste...
Extract Method (Refactoring)   Copyright by IISI. All rights reserved   26
Extract Method – 1 (Eclipse)          Copyright by IISI. All rights reserved   27
Extract Method – 2 (Eclipse)          Copyright by IISI. All rights reserved   28
Extract Method – 3 (Eclipse)          Copyright by IISI. All rights reserved   29
Conditionals and loops also give signs for extractions.Use Decompose Conditional to deal with conditional expressions.With...
Large Class (Bad Smell)• Trying to do too much• Shows up as too many instance  variables• Duplicated code cannot be far  b...
Extract Class(Refactoring)  Copyright by IISI. All rights reserved   32
Extract Class – 1 (Eclipse)         Copyright by IISI. All rights reserved   33
Extract Class – 2 (Eclipse)         Copyright by IISI. All rights reserved   34
Extract Class – 3 (Eclipse)         Copyright by IISI. All rights reserved   35
Long Parameter List        (Bad Smell)• Hard to understand• Become inconsistent and  difficult to use• Forever changing th...
Replace Parameter with Method         (Refactoring)           Copyright by IISI. All rights reserved   37
Preserve Whole Object     (Refactoring)       Copyright by IISI. All rights reserved   38
Introduce Parameter Object       (Refactoring)         Copyright by IISI. All rights reserved   39
Introduce Parameter Object –        01 (Eclipse)          Copyright by IISI. All rights reserved   40
Introduce Parameter Object –        02 (Eclipse)          Copyright by IISI. All rights reserved   41
Introduce Parameter Object –        03 (Eclipse)          Copyright by IISI. All rights reserved   42
Comments (Bad Smell)• They are sweet smell• Dont use as a deodorant            Copyright by IISI. All rights reserved   43
Conclusion
How to refactor safely?        Copyright by IISI. All rights reserved   45
Unit Test  Copyright by IISI. All rights reserved   46
Copyright by IISI. All rights reserved   47
How about the translation?         Copyright by IISI. All rights reserved   48
中譯你可以選擇每個 class 和函式的名字, 這給了你一個解釋自己意圖的機會。 class 或函式內部則解釋實現這個意圖 的作法。如果class 和函式內部又以「 更小單元的意圖」來編寫,你所寫的 程式碼就可以「與其結構中的大部分 重要資訊溝...
原文Choosing the name of each class and the name of each method gives you an opportunity to explain what you intend. The int...
Copyright by IISI. All rights reserved   51
我的翻譯你可以選擇每個 class 和函式的名字, 這給了你一個解釋自己意圖的機會。 class 或函式內部則解釋實現這個意圖 的作法。如果class 和函式內部又以「 更小單元的意圖」來編寫,你所寫的 程式碼就可以「表達出它自己結構的 大部分...
盡信書不如無書  Copyright by IISI. All rights reserved   53
Copyright by IISI. All rights reserved   54
琴鍵有限,琴藝無限   Copyright by IISI. All rights reserved   55
- Thank You -Headquarter6F., No.7, Sec. 2, Xianmin Blvd., Banqiao Dist., New Taipei City 22041, Taiwan(R.O.C.)TEL : +886-2...
Upcoming SlideShare
Loading in …5
×

Refactoring

1,899 views

Published on

Published in: Technology
  • Be the first to comment

Refactoring

  1. 1. RefactoringImproving The Design of Existing Code Reporter:Jiayun Zhou <jiayun.zhou@iisigroup.com> Date :2011/07/13
  2. 2. OutlineIntroductionBad Smells & RefactoringsConclusion Copyright by IISI. All rights reserved 2
  3. 3. Introduction
  4. 4. Eclipse 1.0 – Nov 2001 Copyright by IISI. All rights reserved 4
  5. 5. Eclipse 2.0 – Jun 2002 Copyright by IISI. All rights reserved 5
  6. 6. Eclipse 2.1 – Mar 2003 Copyright by IISI. All rights reserved 6
  7. 7. Eclipse 3.7 – Jun 2011 Copyright by IISI. All rights reserved 7
  8. 8. Copyright by IISI. All rights reserved 8
  9. 9. Martin Fowler Copyright by IISI. All rights reserved 9
  10. 10. Kent Beck Copyright by IISI. All rights reserved 10
  11. 11. Bad Smells & Refactorings
  12. 12. Bad SmellIf it stinks, change it. -Grandma Beck, discussing child-rearing philosophy Copyright by IISI. All rights reserved 12
  13. 13. WTFCopyright by IISI. All rights reserved 13
  14. 14. What the Fxxk Copyright by IISI. All rights reserved 14
  15. 15. Copyright by IISI. All rights reserved 15
  16. 16. Good Programmer• 30% Good Habits• 30% English• 40% Passion, Talent, Practice, and Everything Else Copyright by IISI. All rights reserved 16
  17. 17. Duplicated Code (Bad Smell) DRY (Dont Repeat Yourself) Copyright by IISI. All rights reserved 17
  18. 18. Duplicated Code (Bad Smell) DRY (Dont Repeat Yourself) vs. WET (We Enjoy Typing) Copyright by IISI. All rights reserved 18
  19. 19. Pull Up Method (Refactoring) Copyright by IISI. All rights reserved 19
  20. 20. Pull Up – 1 (Eclipse) Copyright by IISI. All rights reserved 20
  21. 21. Pull Up – 2 (Eclipse) Copyright by IISI. All rights reserved 21
  22. 22. Pull Up – 3 (Eclipse) Copyright by IISI. All rights reserved 22
  23. 23. Pull Up – 4 (Eclipse) Copyright by IISI. All rights reserved 23
  24. 24. Pull Up – 5 (Eclipse) Copyright by IISI. All rights reserved 24
  25. 25. Long Method (Bad Smell)• Short methods are good• Whenever we feel the need to comment something, we write a method instead• Method name explains the intention Copyright by IISI. All rights reserved 25
  26. 26. Extract Method (Refactoring) Copyright by IISI. All rights reserved 26
  27. 27. Extract Method – 1 (Eclipse) Copyright by IISI. All rights reserved 27
  28. 28. Extract Method – 2 (Eclipse) Copyright by IISI. All rights reserved 28
  29. 29. Extract Method – 3 (Eclipse) Copyright by IISI. All rights reserved 29
  30. 30. Conditionals and loops also give signs for extractions.Use Decompose Conditional to deal with conditional expressions.With loops, extract the loop and the code within the loop into its own method. Copyright by IISI. All rights reserved 30
  31. 31. Large Class (Bad Smell)• Trying to do too much• Shows up as too many instance variables• Duplicated code cannot be far behind Copyright by IISI. All rights reserved 31
  32. 32. Extract Class(Refactoring) Copyright by IISI. All rights reserved 32
  33. 33. Extract Class – 1 (Eclipse) Copyright by IISI. All rights reserved 33
  34. 34. Extract Class – 2 (Eclipse) Copyright by IISI. All rights reserved 34
  35. 35. Extract Class – 3 (Eclipse) Copyright by IISI. All rights reserved 35
  36. 36. Long Parameter List (Bad Smell)• Hard to understand• Become inconsistent and difficult to use• Forever changing them as you need more data Copyright by IISI. All rights reserved 36
  37. 37. Replace Parameter with Method (Refactoring) Copyright by IISI. All rights reserved 37
  38. 38. Preserve Whole Object (Refactoring) Copyright by IISI. All rights reserved 38
  39. 39. Introduce Parameter Object (Refactoring) Copyright by IISI. All rights reserved 39
  40. 40. Introduce Parameter Object – 01 (Eclipse) Copyright by IISI. All rights reserved 40
  41. 41. Introduce Parameter Object – 02 (Eclipse) Copyright by IISI. All rights reserved 41
  42. 42. Introduce Parameter Object – 03 (Eclipse) Copyright by IISI. All rights reserved 42
  43. 43. Comments (Bad Smell)• They are sweet smell• Dont use as a deodorant Copyright by IISI. All rights reserved 43
  44. 44. Conclusion
  45. 45. How to refactor safely? Copyright by IISI. All rights reserved 45
  46. 46. Unit Test Copyright by IISI. All rights reserved 46
  47. 47. Copyright by IISI. All rights reserved 47
  48. 48. How about the translation? Copyright by IISI. All rights reserved 48
  49. 49. 中譯你可以選擇每個 class 和函式的名字, 這給了你一個解釋自己意圖的機會。 class 或函式內部則解釋實現這個意圖 的作法。如果class 和函式內部又以「 更小單元的意圖」來編寫,你所寫的 程式碼就可以「與其結構中的大部分 重要資訊溝通」。 (p.61) Copyright by IISI. All rights reserved 49
  50. 50. 原文Choosing the name of each class and the name of each method gives you an opportunity to explain what you intend. The internals of the class or method explain how the intention is realized. If the internals also are written in terms of intention in yet smaller pieces, you can write code that communicates most of the important information about its own structure. Copyright by IISI. All rights reserved 50
  51. 51. Copyright by IISI. All rights reserved 51
  52. 52. 我的翻譯你可以選擇每個 class 和函式的名字, 這給了你一個解釋自己意圖的機會。 class 或函式內部則解釋實現這個意圖 的作法。如果class 和函式內部又以「 更小單元的意圖」來編寫,你所寫的 程式碼就可以「表達出它自己結構的 大部分重要資訊」。 Copyright by IISI. All rights reserved 52
  53. 53. 盡信書不如無書 Copyright by IISI. All rights reserved 53
  54. 54. Copyright by IISI. All rights reserved 54
  55. 55. 琴鍵有限,琴藝無限 Copyright by IISI. All rights reserved 55
  56. 56. - Thank You -Headquarter6F., No.7, Sec. 2, Xianmin Blvd., Banqiao Dist., New Taipei City 22041, Taiwan(R.O.C.)TEL : +886-2-8969-1969 FAX : +886-2-8969-3359

×