Before you start
Instead of writing new applications from scratch, much of a developer's job today involves changing existing code. Simple changes may consist of adding on to the existing code. However, as multiple revisions or extensive changes are made, the internal structure of the software may begin to deteriorate. It can become difficult to understand, and expensive to modify and maintain. That is why it is important to know how to refactor code. Refactoring is changing the internal structure of software to make that software easier to understand and cheaper to modify without changing its observable behavior. In this tutorial, you'll learn about features in WebSphere Studio Application Developer that make refactoring easy.
Who should take this tutorial?
This tutorial assumes that you have experience developing applications with the Java platform. Experience with WebSphere Studio Application Developer (sometimes referred to in this tutorial as Application Developer) is helpful but is not required.
The focus of this tutorial is the refactoring of Java applications using JUnit and the refactoring tools available in Application Developer. If you are unfamiliar with JUnit, you may benefit from completing an earlier WebSphere Developer Domain tutorial, Keeping critters out of your code (see Resources ). We also encourage you to learn more about JUnit and Application Developer after completing this tutorial; see Resources for suggested reading.
You'll need the following software installed on your system to complete the steps in this tutorial:
- WebSphere Studio Application Developer, Version 5.0.
-
goforit2.zip. This is a small slice of the Go-ForIt application, which we'll use as a starting point for the tutorial. The zip archive contains a set of incomplete Java classes that we'll test and complete. You can download this package to your own system for reference.
The GoForIt application was developed by the IBM Developer Relations Technical Consulting team using extreme programming (XP). It is a Web site for the fictitious company Go-ForIt.com, which is a personal errand service. A customer registers at the site and posts an errand that needs to be done, such as picking up laundry, walking the dog, standing in line at the driver's license bureau, and so on. Independent contractors known as personal assistants (PAs) can also register at the site and bid on posted errands. Go-ForIt.com matches up the winning bid with the customer in need and collects a percentage of the fee paid for completion of the errand.
One of the tenets of extreme programming is test-driven development. Test-driven development requires that functional tests be written before functional code. Development effort is then focused on ensuring that all tests are passed.
In his influential book Refactoring: Improving the Design of Existing Code (see Resources), Martin Fowler offers a pair of useful definitions:
- A refactoring is a change in the internal structure of software that makes that software easier to understand and cheaper to modify without changing its observable behavior.
- To refactor is to restructure code by applying a series of syntactic changes without changing the code's observable behavior.
JUnit, a unit-testing framework for the Java language, is an open source project begun by Kent Beck and Erich Gamma. It is the most well-known testing framework in the Java developer community and has also been ported to many other languages.
WebSphere Studio Application Developer
WebSphere Studio Application Developer is IBM's premier integrated development environment (IDE) for J2EE developers and Java programmers. It is based on the WebSphere Studio Workbench, IBM's tool integration platform. WebSphere Studio Workbench is in turn built on the open source Eclipse platform. Eclipse.org (see Resources) is a consortium of development tool providers working to provide a common platform for seamless integration of tools from different vendors.
Application Developer's user interface is centered around the idea of perspectives. A perspective is a group of related views and editors. Application Developer contains several perspectives intended for role-based development. For example, a Web developer might use the Web perspective, while an EJB developer might use the J2EE perspective.

