Code Refactoring - List of Refactoring Techniques

List of Refactoring Techniques

Here are some examples of micro-refactorings; some of these may only apply to certain languages or language types. A longer list can be found in Fowler's Refactoring book and on Fowler's Refactoring Website. Many development environments provide automated support for these micro-refactorings. For instance, a programmer could click on the name of a variable and then select the "Encapsulate field" refactoring from a context menu. The IDE would then prompt for additional details, typically with sensible defaults and a preview of the code changes. After confirmation by the programmer it would carry out the required changes throughout the code.

  • Techniques that allow for more abstraction
    • Encapsulate Field – force code to access the field with getter and setter methods
    • Generalize Type – create more general types to allow for more code sharing
    • Replace type-checking code with State/Strategy
    • Replace conditional with polymorphism
  • Techniques for breaking code apart into more logical pieces
    • Componentization breaks code down into reusable semantic units which present clear, well-defined, simple-to-use interfaces.
    • Extract Class moves part of the code from an existing class into a new class.
    • Extract Method, to turn part of a larger method into a new method. By breaking down code in smaller pieces, it is more easily understandable. This is also applicable to functions.
  • Techniques for improving names and location of code
    • Move Method or Move Field – move to a more appropriate Class or source file
    • Rename Method or Rename Field – changing the name into a new one that better reveals its purpose
    • Pull Up – in OOP, move to a superclass
    • Push Down – in OOP, move to a subclass

Read more about this topic:  Code Refactoring

Famous quotes containing the words list of, list and/or techniques:

    Do your children view themselves as successes or failures? Are they being encouraged to be inquisitive or passive? Are they afraid to challenge authority and to question assumptions? Do they feel comfortable adapting to change? Are they easily discouraged if they cannot arrive at a solution to a problem? The answers to those questions will give you a better appraisal of their education than any list of courses, grades, or test scores.
    Lawrence Kutner (20th century)

    Weigh what loss your honor may sustain
    If with too credent ear you list his songs,
    Or lose your heart, or your chaste treasure open
    To his unmastered importunity.
    William Shakespeare (1564–1616)

    It is easy to lose confidence in our natural ability to raise children. The true techniques for raising children are simple: Be with them, play with them, talk to them. You are not squandering their time no matter what the latest child development books say about “purposeful play” and “cognitive learning skills.”
    Neil Kurshan (20th century)