# Refactoring Catalog

From Refactoring - Improving the Design of Existing Code - Martin Fowler with contribution by Kent Beck

# A First Set of Refactorings

# Extract Function

formerly: Extract Method
inverse of: Inline Function

# Inline Function

formerly: Inline Method
inverse of: Extract Function

# Extract Variable

formerly: Introduce Explaining Variable
inverse of: Inline Variable

# Inline Variable

formerly: Inline Temp
inverse of: Extract Variable

# Change Function Declaration

aka: Rename Function
formerly: Rename Method
formerly: Add Parameter
formerly: Remove Parameter
aka: Change Signature

A good name allows me to understand what function does.

# Encapsulate Variable

formerly: Self-Encapsulate Field
formerly: Encapsulate Field

I want to move widely accessed data

# Rename Variable

# Introduce Parameter Object

See a groups of data items that regularly travel together, appearing in function after function.

  • makes explicit the relationship between data items
  • reduces size of parameter lists
  • helps consistency since all functions that use the structure
  • can move behavior into the new class

# Combine Functions into Class

See a group of functions that operate closely together on common body of data.

  • form functions => more explicit, simplify function calls inside the object by removing many of the args
  • provides a reference to pass such an object to other pars of the system
  • allows client to mutate the core data of the object, and the derivations remain consistent.

# Combine Functions into Transform

# Split Phase

# Encapsulation

# Encapsulate Record

formerly: Replace Record with Data Class

# Encapsulate Collection

# Replace Primitive with Object

# Replace Temp With Query

# Extract Class

inverse of: Inline Class

# Inline Class

inverse of: Extract Class

# Hide Delegate

inverse of: Remove Middle Man

# Remove Middle Man

inverse of: Hide Delegate

TIP

I can do a mixture here. Some delegations may be so common that I'd like to keep them to make client code easier to work with.

# Substitute Algorithm

# Moving Features

# Move Function

formerly: Move Method

# Move Field

# Move Statements into Functions

inverse of: Move Statements into Callers

# Move Statements into Callers

inverse of: Move Statements into Functions

# Replace Inline Code with Function Call

# Slide Statements

formerly: Consolidate Duplicate Conditional Fragment

# Split Loop

# Replace Loop with Pipeline

# Remove Dead Code

# Organizing Data

# Split Variable

formerly: Consolidate Duplicate Conditional Fragment
formerly: Consolidate Duplicate Conditional Fragment

# Rename Field

# Replace Derived Variable with Query

# Change Reference to Value

inverse of: Change Value to Reference

# Change Value to Reference

inverse of: Change Reference to Value

# Simplifying Conditional Logic

# Decompose Conditional

# Consolidate Conditional Expression

# Replace Nested Conditional with Guard Clauses

# Replace Conditional with Polymorphism

# Introduce Special Case

formerly: Introduce Null Object

# Introduce Assertion

# Refactoring APIs

# Separate Query from Modifier

# Parameterize Function

formerly: Parameterize Method

# Remove Flag Argument

formerly: Replace Parameter with Explicit Methods

# Preserve Whole Object

# Replace Parameter with Query

formerly: Replace Parameter with Method
inverse of: Replace Query with Parameter

# Replace Query with Parameter

inverse of: Replace Parameter with Query

# Remove Setting Method

# Replace Constructor with Factory Function

formerly: Replace Constructor with Factory Method

# Replace Function with Command

formerly: Replace Method with Method Object
inverse of: Replace Command with Function

# Replace Command with Function

inverse of: Replace Function with Command

# Dealings with Inheritance

# Pull Up Method

inverse of: Push Down Method

# Pull Up Field

inverse of: Push Down Field

# Pull up Constructor body

# Push Down Method

inverse of: Pull Up Method

# Push Down Field

inverse of: Pull Up Field

# Replace Type Code with Subclasses

subsummes: Replace Type Code with State/Strategy
subsummes: Extract Subclass
inverse of: Remove Subclass

# Remove Subclass

formerly: Replace Subclass with Fields
inverse of: Replace Type Code with Subclasses

# Extract Superclass

# Replace Subclass with Delegate

# Replace Superclass with Delegate

formerly: Replace Inheritance with Delegation