Refactoring Improving the Design of Existing Code

1. Bad smells in code

2. Duplicated code

  • when same expression, Extract Method
  • sibling in subclass,extract method and pulll up method in super class
  • similar code ,but not identical,will extract Template method

3. Long Method

  • long Method is difficult understand.
  • small Method name will explain function.
  • logic in loop  will extract method
  • replace method with method object
  • decompose conditional

4. Large Class

  • many instance and duplicated code will happen in large class
  • extarct subclass
  • extarct interface group by function
  • duplicate observed Data

5. Long Parameter List

  • difficulte to understand paramter
  • Preserve whole object

6. Divergent Change

7. Shotgun Surgery

  • Move method and move field in one class

8. Feature Envy

9. Data Clumps

10. Primitive Obsession

  • record type
  • primitive types

11. Switch Statements

  • cause by type code
  • replace type code with subclasses
  • replace type with state/strategy
  • replace conditional with polymorphism
  • replace parameter with Explicit methods

12. Parallel inheritance hieratchies

  • same pre in other class is bad smell

13. Lazy Class

14. Speculative generality

你可能感兴趣的:(Refactoring Improving the Design of Existing Code)