Causes for refactoring Code duplicating; Huge method; Huge or deep loops; Bad class coherency; Bad interface agreement (Interface monster); Too many parameters in method; Too much class’s responsibilities;
Causes for refactoring It’s necessary to make changes in several classes; It’s necessary to change several hierarchies; It’s necessary to make changes in several case blocks; Coherent data placed not in a class; Method use more parameters from other class than its; Elementary type is overload;
Causes for refactoring Class has limited functionality; Method gets Tramp data; One class knows too much about another one; Method has unlucky name; Public fields; Inherited class used small dime of base methods; Code Comments; Class contains methods that could be some time;
Data Refactoring Magic numbers; Unlucky variable name; Temporary variable using; Multiple usage of the same variable; Enum usage; Basic type expansion;
Operator Refactoring Decomposition of expression; Extract Boolean methods; Immediate exit from method; Polymorphism usage; Dummy objects usage;
Methods Refactoring Method extraction; Inline method; Class extraction from huge methods; Additional parameters usage; Redundant parameters deletion; Pass whole class instead of several parameters; Return base classes;
Class Refactoring Value to Reference types replacement; Reference to Value types replacement; Move fields/properties/methods to base class; Move fields/properties/methods to inherited class; Move methods to another class; Split one class to many; Delete useless class; Use extension methods;
Class Refactoring Replace inheritance to delegating; Replace delegating to inheritance; Data encapsulating; Unite inherited and base class.
Safe Refactoring Save original code; Make refactoring step-by-step; Create list of actions; Create To-Do list; Create check points; Monitor warnings from compiler; Make change-reviews.
Bad causes to do refactoring Do not expect refactoring to correct your code; Do not wait for some magic from refactoring.
Refactoring strategies Use refactoring when you: Create new methods; Create new classes; Fix defects; Create refactoring in bug’s potential code; Create refactoring in complicated modules.