Monthly Archives: August 2009

Refactoring Day 12 : Break Dependencies

Today’s refactoring is useful if you are trying to introduce unit tests into your code base as testing “seams” are needed to properly mock/isolate areas you don’t wish to test. In this example we have client code that is using … Continue reading 

Posted in Uncategorized | 4 Comments

Refactoring Day 11 : Switch to Strategy

Todays refactoring doesn’t come from any one source, rather I’ve used different versions over the years and I’m sure other have different variations of the same aim. This refactoring is used when you have a larger switch statement that continually … Continue reading 

Posted in Uncategorized | 5 Comments

Refactoring Day 10 : Extract Method

Today we look at the Extract Method refactoring. This is an extremely easy refactoring with several benefits. First, it helps to make code more readable by placing logic behind descriptive method names. This reduces the amount of investigation the next … Continue reading 

Posted in Uncategorized | 4 Comments

Refactoring Day 9 : Extract Interface

Today we look at an often overlooked refactoring. Extract Interface. When you notice more than one class using a similar subset of methods on a class, it is useful to break the dependency and introduce an interface that the consumers … Continue reading 

Posted in Uncategorized | 1 Comment

Refactoring Day 8 : Replace Inheritance with Delegation

All too often inheritance is used in the wrong scenarios. Inheritance should only be used in logical circumstances but it is often used for convenience purposes. I’ve seen this many times and it leads to complex inheritance hierarchies that don’t … Continue reading 

Posted in Uncategorized | 3 Comments

Refactoring Day 7 : Rename (method, class, parameter)

This refactoring I use most often and is one of the most useful refactoring. All too often we do not name methods/classes/parameters properly that leads to a misunderstanding as to what the method/class/parameter’s function is. When this occurs, assumptions are … Continue reading 

Posted in Uncategorized | Leave a comment

Refactoring Day 6 : Push Down Field

Opposite of the Pull Up Field refactoring is push down field. Again, this is a pretty straight forward refactoring without much description needed 1: public abstract class Task 2: { 3: protected string _resolution; 4: } 5:  6: public class … Continue reading 

Posted in Uncategorized | 2 Comments

Refactoring Day 5 : Pull Up Field

Today we look at a refactoring that is similar to the Pull Up method. Instead of a method, it is obviously done with a field instead! 1: public abstract class Account 2: { 3: } 4:  5: public class CheckingAccount … Continue reading 

Posted in Uncategorized | 3 Comments

Refactoring Day 4 : Push Down Method

Yesterday we looked at the pull up refactoring to move a method to a base class so mutiple derived classes can use a method. Today we look at the opposite. Here is the code before the refactoring: 1: public abstract … Continue reading 

Posted in Uncategorized | 6 Comments

Refactoring Day 3 : Pull Up Method

The Pull Up Method refactoring is the process of taking a method and “Pulling” it up in the inheritance chain. This is used when a method needs to be used by multiple implementers. 1: public abstract class Vehicle 2: { … Continue reading 

Posted in Uncategorized | 1 Comment