Refactoring

Refactoring

Refactoring is the process of changing a software system in such a way that it does not alter the external behavior of the code yet improves its internal structure.

Code smell

Code smell is any symptom in the source code of a program that possibly indicates a deeper problem. Code smells are usually not bugs they are not technically incorrect and don't currently prevent the program from functioning. Instead, they indicate weaknesses in design that may be slowing down development or increasing the risk of bugs or failures in the future.

The Refactoring Cycle

Duplicated Code

Problems

What to Do

Long Method

Problems

What to Do

Long Parameter List

Problems

What to Do

Uncommunicative Name

A name doesn't communicate its intent well enough. Examples of this can include:

Problems

What to Do

Comments

Problems

Don’t delete comments that are pulling their own weight such as rdoc API documentation.

What to Do

Large Class or Module

Problems

What to Do

Shotgun Surgery

Problems

What to Do

Feature Envy

Problems

What to Do

Data Clump

Problems

What to Do

Special Case

Problems

What to Do

Control Coupling

Problems

What to Do

Greedy Method

Problems

What to Do

Divergent Change

Problems

What to Do

Dead Code

Problems

What to Do

Lazy Class

Problems

When to Leave It

Sometimes, a Lazy Class is present to communicate intent. You may have to balance communication versus simplicity in your design; and when communication wins, leave the Lazy Class in place.

What to Do

Temporary Field

Problems

When to Leave It

It may not be worth the trouble of creating a new class if it doesn’t represent a useful abstraction.

What to Do

Message Chain

What to Do

Extract Method

Extract Method

Inline Method

Inline Method

Extract Class

Extract Class

Inline Class

Inline Class

Extract Module

Extract Module

Pull Up Method

Pull Up Method

Rename Method

Rename Method

Move Field

Move Field

Form Template Method

Form Template Method

Parameterize Method

Parameterize Method

Separate Query From Modifier

Separate Query From Modifier

Hide Delegate

Hide Delegate

Introduce assertion

Introduce assertion

Introduce Null Object

Introduce Null Object

Replace Parameter With Method

Replace Parameter With Method

Preserve Whole Object

Preserve Whole Object

Introduce Parameter Object

Introduce Parameter Object

Replace Array With Object

Replace Array With Object

Replace Method With Method Object

Replace Method With Method Object

Replace Temp With Query

Replace Temp With Query

Replace Type Code With Polymorphism

Replace Type Code With Polymorphism

Replace Type Code With Module Extension

Replace Type Code With Module Extension

Replace Type Code With State Strategy

Replace Type Code With State Strategy

Substitute Algorithm

Substitute Algorithm

Decompose conditional

Decompose conditional

Replace Loop with Collection Closure Method

Replace Loop with Collection Closure Method

Introduce Named Parameter

Introduce Named Parameter

/

#