原创 2004年10月21日 23:48:00

Reasons to refactor:
1. Code is duplicated.
2. A routine is too long.
3. A loop is too long or too deeply nested.
4. A class has poor cohesion.
5. A class interface does not provide a consistent level of abstraction.
6. A parameter list has too many parameters.
7. Changes within a class tend to be compartmentalized.
8. Changes require parallel modification to multiple classes.
9. Inheritance hierarchies have to be modified in parallel.
10. case statement have to be modified in parallel.
11. Related data items that are used together are not organized into calss.
12. A routine uses more features of another class than of its own class.
13. A primitive data type is overlaoded.
14. A class doesn't do very much.
15. A chain of routines passes tramp data
16. A middle man object isn't doing anything.
17. One class is overly intimate with another.
18. A routine has a poor name.
19. Data memebers are public.
20. A subclass uses only a small percentage of its parents' routines.
21. Comments are used to explain difficult code.
22. Global variables are used.
23. A routine uses setup code before a routine call or takedown code after a routine call.
24. A program contains code that seems like it might be needed someday.

Specific refactorings:
I think it's better to refer it to the book: Refactoring.

Keys to refactoring safely:
1. Save the code you start with
2. Keep refactoring small.
3. Do refactoring one at a time.
4. Make a list of steps you intend to take.
5. Make a parking lot.
6. Make frequent checkpoints.
7. Retest.
8. Add test cases.
9. Review the changes.
10. Adjust your approach depending on the risk level of the refactoring.

Bad time to refactor
1. Don't use refactoring as a cover for code and fix.
2. Avoid refactoring instead of rewriting.

Refactoring startegies.
1. Refactor when you add a routine.
2. Refactor when you add a class.
3. Refactor when you fix a defect.
4. Target error-prone modules.
5. Target high complexity modules.
6. In a maintenance environment, improve the parts you touch.
7. Define an interface between clean code and ugly code, and then move code across the interface.

《Refactoring-Improving the Design of Existing Code》读书笔记

重构的目的是让可以工作的代码更好,使面向对象的代码更简单,更容易维护。书上还说,所有的程序员应当能使用重构技术改进他们的代码。   nuts-and-bolts n.具体细节   前言   ...
  • backard
  • backard
  • 2013年01月27日 23:53
  • 344

重构模式(五)---- Refactoring和方法

  • casularm
  • casularm
  • 2004年10月23日 12:31
  • 1444

intellij idea小技巧

1.intellij idea重构变量名 intellij idea重构变量名 talking 为speaking 步骤如下: 1.在talking上 shift+F6 2.弹出对话框中 将talk...
  • wulong710
  • wulong710
  • 2015年03月21日 17:22
  • 807

CScout: A Refactoring Browser for C

CScout: A Refactoring Browser for C Diomidis Spinellis Athens University of Economics and Busine...
  • gxp
  • gxp
  • 2012年03月28日 11:01
  • 2568

CScout: The C Refactoring Browser

CScout: The C Refactoring Browser CScout is a source code analyzer and refactoring browser forcolle...
  • gxp
  • gxp
  • 2012年03月28日 10:01
  • 681


一、什么是重构? 重构(Refactoring)这个词最初由Martin Fowler 和 Kent Beck给下的定义,它是 一种修改,使软件的内部结构更容易理解,在不改变软...
  • a511596982
  • a511596982
  • 2012年12月16日 12:27
  • 4624

php-refactoring-browser, PHP的命令行 重构工具

php-refactoring-browser, PHP的命令行 重构工具 源代码名称:php-refactoring-browser源代码网址:
  • dowemo
  • dowemo
  • 2017年11月24日 16:49
  • 101

什么是重构 - Refactoring

重构(Refactoring)就是在不改变软件现有功能的基础上,通过调整程序代码改善软件的质量、性能,使其程序的设计模式和架构更趋合理,提高软件的扩展性和维护性。另有同名图书。 重构的好处 ...
  • Giberson1
  • Giberson1
  • 2012年11月08日 09:10
  • 1117

C++ Refactoring in Visual Studio 2015

Visual C++ 官方的 Refactoring 插件始于 Visual C++ 2013 的一个免费插件:Visual C++ Refactoring。在这个插件出现之前,相信很多人是在用(盗版...
  • XinYaping
  • XinYaping
  • 2016年07月08日 10:58
  • 825

Refactoring to Patterns

模式是面向对象设计的基石,而测试优先的编程方法和大刀阔斧的重构则是进化式设计的基石。为了避免过分设计或者设计不足,我们有必要学习如何让模式适应新的、渐进式的软件开发节奏。——Joshua Keriev...
  • superlmj
  • superlmj
  • 2005年01月07日 18:29
  • 818