What Is Prefactoring

Prefactoring is the application of past experience to the creation of new software systems. Past experience includes both your own and that of others, particularly lessons learned from refactoring. The experience is captured in a number of guidelines that can be easily applied to the development process.

In This Article:

You probably have heard of refactoring, the process of restructuring code without changing its external behavior. Refactoring was made popular by Martin Fowler and his book, Refactoring: Improving the Design of Existing Code. Prefactoring does not imply that you will never need to refactor your code. But it may help you to create more readable and maintainable code, as well as to make design decisions that are more amenable to refactoring.

Prefactoring has a number of guidelines that suggest ways to proceed with your development. The guidelines have been gathered from the experiences of many programmers over the years. My book, Prefactoring, lists guidelines in the areas of Extreme Abstraction, Extreme Separation, and Extreme Readability, as well as general ones. I'll cover a few of the guidelines in this article.

Extreme Abstraction

The "When You're Abstract, Be Abstract All the Way" guideline states that you should define all your data with abstract data types, rather than primitive data types. Abstract data types usually have additional behavior that can be encapsulated within the type. For example, any variable or field that represents a dollar amount should be declared as a Dollar, rather than a double. The Dollar type can include functionality for converting it to and from a string, as well as appropriate arithmetic functions such as add and subtract. The class might appear as:

With the functionality and details contained within the data type, you are less likely to create duplicate code. If you find you need additional functionality for Dollar, you already have the class in which to put it.

In addition, with abstract data types, your code becomes more readable. You can concentrate on the solution to the overall problem, rather than the specific details. For example, consider: