Refactoring - Improving The Design Code

This is just a summary. For complete detail please refer to the book written by Martin Fowler.

Why Should You Refactor


  • Improves the design of softwaren
  • Makes software easier to understand
  • Helps you find bugs
  • Helps you program faster

When Should You Refactor

  • When you do something similar three times.
  • When you add function
  • When you need to fix a bug
  • When you do a code review

What Should You Refactor
  • Duplicated code
  • Long method
  • Large class
  • Long parameter list
  • Divergent change
  • Shotgun Surgery - the opposite of divergent change, everytime you make a kind of change, you have to make a lot of little changes to a lot of different classes.
  • Comments - good codes don't need long comments.
  • Lazy class
  • Temporary field
  • etc (refer the book)

How To Refactor
  1. Build unit tests
  2. Run the tests
  3. Commit the codes
  4. Refactor
  5. Run the tests again.
  6. If something goes wrong, fix it until the tests run.
  7. If you can't fix it, revert the codes which is comitted on step 3.
  8. If everything is okay, commit the codes again.

1 comments: (+add yours?)

孟凡振 said...

oh ,u r right we need refactoring ..