Skip to content

Instantly share code, notes, and snippets.

@evanmcclure
Last active May 13, 2020 01:08
Show Gist options
  • Save evanmcclure/38eea41265e8b08fc7bd9ac557fe9fe6 to your computer and use it in GitHub Desktop.
Save evanmcclure/38eea41265e8b08fc7bd9ac557fe9fe6 to your computer and use it in GitHub Desktop.
2-Minute Refactorings

2-Minute Refactorings

This is an outline of the links to my series of expository videos called 2-Minute Refactorings. The content is derived from the second edition of the book Refactoring: Improving The Design of Existing Code by Martin Fowler and the book Refactoring to Patterns by Joshua Kerievsky.

Table of Contents

  1. A Catalog of Refactorings
  2. A Catalog of Refactorings to Patterns

A Catalog of Refactorings

Most Useful

  • Extract Function
  • Inline Function
  • Extract Variable
  • Inline Variable
  • Change Function Declaration
  • Encapsulate Variable
  • Rename Variable
  • Introduce Parameter Object
  • Combine Functions into Class
  • Combime Functions into Transform
  • Split Phase

Encapsulation

  • Encapsulate Record
  • Encapsulate Collection
  • Replace Primitive with Object
  • Replace Temp with Query
  • Extract Class
  • Inline Class
  • Hide Delegate
  • Remove Middleman
  • Substitute Algorithm

Moving Features

  • Move Function
  • Move Field
  • Move Statements into Function
  • Move Statements to Callers
  • Replace Inline Code with Function Call
  • Slide Statements
  • Split Loop
  • Replace Loop with Pipeline
  • Remove Dead Code

Organizing Data

  • Split Variable
  • Rename Field
  • Replace Derived Variable with Query
  • Change Reference to Value
  • Change Value to Reference

Simplifying Conditional Logic

  • Decompose Conditional
  • Consolidate Conditional Expression
  • Replace Nested Conditional with Guard Clauses
  • Replace Conditional with Polymorphism
  • Introduce Special Case
  • Introduce Assertion

Refactoring APIs

  • Separate Query from Modifier
  • Parameterize Function
  • Remove Flag Argument
  • Preserve Whole Object
  • Replace Parameter with Query
  • Replace Query with Parameter
  • Remove Setting Method
  • Replace Constructor with Factory Function
  • Replace Function with Command
  • Replace Command with Function

Dealing with Inheritance

  • Pull Up Method
  • Pull Up Field
  • Pull Up Constructor Body
  • Push Down Method
  • Push Down Field
  • Replace Type Code with Subclasses
  • Remove Subclass
  • Extract Superclass
  • Collapse Hierarchy
  • Replace Subclass with Delegate
  • Replace Superclass with Delegate

A Catalog of Refactorings to Patterns

Creation

  • Replace Constructors with Creation Methods
  • Move Creation Knowledge to Factory
  • Encapsulate Classes with Factory
  • Introduce Polymorphic Creation with Factory Method
  • Encapsulate Composite with Builder
  • Inline Singleton

Simplification

  • Compose Method
  • Replace Conditional Logic with Strategy
  • Move Embellishment to Decorator
  • Replace State-Alerting Conditionals with State
  • Replace Implicit Tree with Composite
  • Replace Conditional Dispatcher with Command

Generalization

  • Form Template Method
  • Extract Composite
  • Replace One/ Many Distinctions with Composite
  • Replace Hard-Coded Notifications with Observer
  • Unify Interfaces with Adapter
  • Extract Adapter
  • Replace Implicit Language with Interpreter

Protection

  • Replace Type Code with Class
  • Limit Instantiation with Singleton
  • Introduce Null Object

Accumulation

  • Move Accumulation to Collecting Parameter
  • Move Acumulation to Visitor

Utilities

  • Chain Constructors
  • Unify Interfaces
  • Extract Parameter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment