Search This Blog

Sunday, February 14, 2010

Code Smells

From Martin Fowler's excellent book, Refactoring: Improving the Design of Existing CodeRefactoring: Improving the Design of Existing Code. More descriptions can be found here.

  • Duplicated Code
  • Long Method
  • Large Class
  • Long Parameter List
  • Divergent Change
  • Shotgun Surgery
  • Feature Envy
  • Data Clumps
  • Primitive Obsession
  • Switch Statements
  • Parallel Inheritance Hierarchies
  • Lazy Class
  • Speculative Generality
  • Temporary Field
  • Message Chains
  • Middle Man
  • Inappropriate Intimacy
  • Alternative Classes with Different Interfaces
  • Incomplete Library Class
  • Data Class
  • Refused Bequest
  • Comments

  • Duplicate code: identical or very similar code exists in more than one location.
  • Large method: a method, function, or procedure that has grown too large.
  • Large class: a class that has grown too large, see God object.
  • Feature envy: a class that uses methods of another class excessively.
  • Inappropriate intimacy: a class that has dependencies on implementation details of another class.
  • Refused bequest: a class that overrides a method of a base class in such a way that the contract of the base class is not honored by derived class. See Liskov substitution principle.
  • Lazy class: a class that does too little.
  • Duplicated method: a method, function, or procedure that is very similar to another.
  • Contrived Complexity: forced usage of overly complicated design patterns where simpler design would suffice.
Checkstyle, PMD and FindBugs for Java, to automatically check for certain kinds of code smells.

No comments:

Post a Comment