Refactoring, A First Example

1,350 views

Published on

Published in: Education, Technology, Business
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,350
On SlideShare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
Downloads
37
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide
  • 08/31/09 06:39 © 2003-2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
  • 08/31/09 06:39 © 2003-2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
  • 08/31/09 06:39 © 2003-2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
  • 08/31/09 06:39 © 2003-2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
  • 08/31/09 06:39 © 2003-2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
  • 08/31/09 06:39 © 2003-2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
  • 08/31/09 06:39 © 2003-2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
  • 08/31/09 06:39 © 2003-2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
  • 08/31/09 06:39 © 2003-2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
  • 08/31/09 06:39 © 2003-2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
  • 08/31/09 06:39 © 2003-2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
  • 08/31/09 06:39 © 2003-2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
  • 08/31/09 06:39 © 2003-2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
  • 08/31/09 06:39 © 2003-2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
  • 08/31/09 06:39 © 2003-2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
  • 08/31/09 06:39 © 2003-2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
  • 08/31/09 06:39 © 2003-2004 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
  • Refactoring, A First Example

    1. 1. Refactoring, a First Example Vorleak Chy (vorleak.chy@gmail.com) Software Engineer Yoolk Inc http://groups.google.com/group/khmertech/
    2. 2. Before Refactoring <ul><li>Unreadable code </li></ul><ul><li>Duplicated code </li></ul><ul><li>Complex code </li></ul><ul><li>Hard to modify </li></ul>
    3. 3. After Refactoring <ul><li>Easier to understand </li></ul><ul><li>Cheaper to modify </li></ul><ul><li>Clean code </li></ul><ul><li>Better code </li></ul>
    4. 4. Introduction <ul><li>What is Refactoring? </li></ul><ul><li>Why Refactor? </li></ul>
    5. 5. What is Refactoring? <ul><li>The process of changing a software system in such a way that it does not alter the external behaviour of the code, yet improves its internal structure . </li></ul><ul><li>Fowler, et al., Refactoring, 1999. </li></ul>
    6. 6. Why Refactor? <ul><li>The reality </li></ul><ul><ul><li>Extremely difficult to get the design “right” the first time </li></ul></ul><ul><ul><li>Hard to fully understand the problem domain </li></ul></ul><ul><ul><li>Hard to understand user requirements, even if the user does! </li></ul></ul><ul><ul><li>Hard to know how the system will evolve in five years </li></ul></ul><ul><ul><li>Original design is often inadequate </li></ul></ul><ul><ul><li>System becomes brittle over time, and more difficult to change </li></ul></ul>
    7. 7. Why Refactor? (Cont.) <ul><li>Refactoring helps you to </li></ul><ul><ul><li>Manipulate code in a safe environment (behavior preserving) </li></ul></ul><ul><ul><li>Recreate a situation where evolution is possible </li></ul></ul><ul><ul><li>Understand existing code </li></ul></ul>
    8. 8. Look in example <ul><li>So what? </li></ul><ul><li>Try to understand in the real example </li></ul>
    9. 9. The Starting Point
    10. 10. Comments on the Starting Program <ul><li>When you find you have to add a feature to a program, and the program's code is not structured in a convenient way to add the feature, first refactor the program to make it easy to add the feature, then add the feature. </li></ul>
    11. 11. The First Step in Refactoring <ul><li>Before you start refactoring, check that you have a solid suite of tests. These tests must be self-checking. </li></ul>
    12. 12. Decomposing and Redistributing the Statement Method (Extract Method) <ul><li>Refactoring changes the programs in small steps. If you make a mistake, it is easy to find the bug. </li></ul><ul><li>Any fool can write code that a computer can understand. Good programmers write code that humans can understand. </li></ul>
    13. 13. Moving the Amount Calculation <ul><li>Move Method </li></ul><ul><li>Replace Temp with Query </li></ul>
    14. 14. Extracting Frequent Renter Points <ul><li>Extract Method </li></ul>
    15. 15. Removing Temps <ul><li>Replace Temp with Query </li></ul>
    16. 16. Replacing the Conditional Logic on Price Code with Polymorphism <ul><li>Moving methods to movie </li></ul>
    17. 17. At last … Inheritance
    18. 19. Thank-you for attending KhmerTech Feel free to join at http://groups.google.com/group/khmertech/

    ×