Home > Articles > Software Development & Management

Introduction to Refactoring to Patterns

  • PrintPrint
  • Share ThisShare This
  • DiscussDiscuss
Refactoring to Patterns

This chapter is from the book
Refactoring to Patterns

Refactoring software by hand can be a real pain. So why not just automate the process? In this chapter, Joshua Kerievsky explains the whys and hows of refactoring, and why you shouldn't trust that automated refactoring program.

In this chapter I offer a few thoughts on what refactoring is and what you need to do to be good at it. This chapter is best read in accompaniment with the chapter "Principles in Refactoring" [F].

What Is Refactoring?

A refactoring is a "behavior-preserving transformation" or, as Martin Fowler defines it, "a change made to the internal structure of software to make it easier to understand and cheaper to modify without changing its observable behavior" [F, 53].

The process of refactoring involves the removal of duplication, the simplification of complex logic, and the clarification of unclear code. When you refactor, you relentlessly poke and prod your code to improve its design. Such improvements may involve something as small as changing a variable name or as large as unifying two hierarchies.

To refactor safely, you must either manually test that your changes didn't break anything or run automated tests. You will have more courage to refactor and be more willing to try experimental designs if you can quickly run automated tests to confirm that your code still works.

Refactoring in small steps helps prevent the introduction of defects. Most refactorings take seconds or minutes to perform. Some large refactorings can require a sustained effort for days, weeks, or months until a transformation has been completed. Even such large refactorings are implemented in small steps.

It's best to refactor continuously, rather than in phases. When you see code that needs improvement, improve it. On the other hand, if your manager needs you to finish a feature before a demo that just got scheduled for tomorrow, finish the feature and refactor later. Business is well served by continuous refactoring, yet the practice of refactoring must coexist harmoniously with business priorities.

  • Share ThisShare This
  • Your Account

Discussions

Refactoring and TDD
Posted Aug 10, 2009 03:23 PM by Steve5840
0 Replies

Make a New Comment

You must log in in order to post a comment.

Related Resources

Stephen MorrisGetting off the ground with your first iPhone app
By Stephen B. Morris on January 13, 20102 Comments

My first iPhone app – “The Day Was…” has now been through two updates. I want to talk a little about how to get started with this interesting technology. As with any software, the first step is having an idea, i.e., one or more requirements.

You Can Check Out Any Time You Like, But You Can Never Leave
By John Traenkenschuh on December 8, 2009 No Comments

Much like the line from the song, "Hotel California", Traenk finds out that membership with key Internet II sites is eternal...

Predictions and Predilections
By John Traenkenschuh on November 23, 2009 No Comments

Leaves are down; harvest is in, for the most part.  Another year comes rushing up to us.  What will it bring?

See All Related Blogs

Informit Network