21.08.2013 Views

Software Engineering for Students A Programming Approach

Software Engineering for Students A Programming Approach

Software Engineering for Students A Programming Approach

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

CHAPTER<br />

13 Refactoring<br />

This chapter:<br />

■ explains how to carry out refactoring<br />

■ explains several common refactorings.<br />

13.1 ● Introduction<br />

Refactoring is about improving an architectural design. Nowadays a design tends to be an<br />

OOD, expressed in terms of classes and their interrelationships (methods). However,<br />

design does not usually proceed in a straight<strong>for</strong>ward, linear manner. Most often, design<br />

tends to be an iterative process. First, candidate classes are identified. Then some will be<br />

accepted while others will be rejected – perhaps because they have no methods or because<br />

their methods are subsumed by some other class. Methods tend to migrate from one class<br />

to another as a better understanding of the objects and their role within the problem<br />

emerges. This process is known as refactoring. Refactoring is the trans<strong>for</strong>mation of a correct<br />

program structure (e.g., a class diagram) into an improved structure.<br />

Good ideas <strong>for</strong> refactoring are published in catalogs. Each idea has a name so that it<br />

can be referred to in conversations between developers. In this chapter we present some<br />

of the most popular refactorings. We use as an example the cyberspace invaders game<br />

(Appendix A) whose architecture is designed in the chapter on OOD.<br />

So, the steps of refactoring are:<br />

1. create a design<br />

2. review the design<br />

3. identify possible refactorings<br />

4. carry out refactoring.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!