blob: ac437b870e679b52d03f70aad2317aff39dcc291 [file] [log] [blame]
<?xml version="1.0" encoding="UTF-8"?>
<org.eclipse.epf.uma:ContentDescription xmi:version="2.0"
xmlns:xmi="http://www.omg.org/XMI" xmlns:org.eclipse.epf.uma="http://www.eclipse.org/epf/uma/1.0.4/uma.ecore"
xmlns:epf="http://www.eclipse.org/epf"
epf:version="1.2.0" xmi:id="-g0jWGmg-E0rCQEmnibTDIA"
name="new_guideline,_OlyWoOX7Edu8VZPtlaU33g" guid="-g0jWGmg-E0rCQEmnibTDIA" changeDate="2007-04-19T05:51:37.878-0700"
version="1.0.0">
<mainDescription>&lt;p> Refactoring involves improving the design of existing code without changing &#xD;
the system's behavior. It is explicitly not about adding or changing behavior, &#xD;
but about improving the design of existing behavior. &lt;/p>&#xD;
&lt;p> A full set of developer tests is required before refactoring can be applied. &#xD;
It is critical that the system behavior be in a known, verifiably correct state &#xD;
before modifying the design so that you can improve the design without fear &#xD;
that the modified implementation will break something. Refactoring is a safe &#xD;
transformation to improve code, but it is safe only if there are tests that &#xD;
can verify that the system still works as intended. &lt;/p>&#xD;
&lt;p> Before refactoring, there must be full developer test coverage of the area &#xD;
of the system under consideration. Then refactoring is initiated when an area &#xD;
that needs improvement is identified in the system by examining either the code &#xD;
or&amp;nbsp;some other&amp;nbsp;representation of the design. The issues identified &#xD;
are sometimes called &quot;smells.&quot;&lt;/p>&#xD;
&lt;p> Here are several smells to look for that might lead to refactoring: &lt;/p>&#xD;
&lt;ul>&#xD;
&#xD;
&lt;li> &lt;b>Duplicated code: &lt;/b>Duplicated code makes the system harder to understand &#xD;
and harder to maintain. &lt;/li>&#xD;
&lt;li>&lt;b> Large design element or method: &lt;/b>Large design elements or methods &#xD;
diminish the ability of people to understand the design, reduce the potential &#xD;
for reuse, and make developer testing more difficult. &lt;/li>&#xD;
&lt;li> &lt;b>Poorly named element:&lt;/b> Whether the element be a variable, function, &#xD;
class, or component, its name should connote what it is so that the code can &#xD;
be maintained. &lt;/li>&#xD;
&lt;li>&lt;b> Tight coupling: &lt;/b>Each design element should work with minimal concern &#xD;
for the internal aspects of other design elements. Otherwise, changes to one &#xD;
element can have undesirable effects in other elements. &lt;/li>&#xD;
&lt;/ul>&#xD;
&lt;p> As you can see from this list, refactoring can improve the &amp;quot;internals&amp;quot; &#xD;
of a design element, the interface of the element, or the relationships and &#xD;
collaboration between elements. Also, many of the smells&amp;nbsp;are characterized &#xD;
as making the software more difficult to understand; whereas refactoring is &#xD;
about making the system simpler. &lt;/p>&#xD;
&lt;p> After an issue is identified, a refactoring method can be selected that will &#xD;
improve the situation. There are catalogs of refactoring methods available that &#xD;
are change patterns that will fix common problems while retaining the behavior &#xD;
of the system. &lt;/p>&#xD;
&lt;p> These are examples of refactoring methods:&lt;/p>&#xD;
&lt;ul>&#xD;
&#xD;
&lt;li> &lt;b>Extract Method:&lt;/b> Pull out the duplicated code into its own single &#xD;
method or extract part of a large method into its own method. &lt;/li>&#xD;
&lt;li> &lt;b>Extract Class: &lt;/b>Pull some cohesive part of a class into its own class &#xD;
to reduce the size of a design element that is too big. &lt;/li>&#xD;
&lt;li>&lt;b> Rename Method, Rename Class, or Rename Variable: &lt;/b>Give a more meaningful &#xD;
name to an element. &lt;/li>&#xD;
&lt;li>&lt;b> Extract Interface: &lt;/b>Create a clean interface to an element to reduce &#xD;
coupling. &lt;/li>&#xD;
&lt;/ul>&#xD;
&lt;p> When refactoring has been applied, developer tests are run again to ensure &#xD;
that the system still behaves correctly. It is important that the system is &#xD;
working correctly after each small refactoring. Although many refactorings can &#xD;
be put together to drive broad change across the code base, the tests should &#xD;
run correctly between each refactoring applied. Refactoring must be applied &#xD;
as small behavior-preserving transformations. &lt;/p>&#xD;
&lt;p> As mentioned previously, refactoring requires full developer test coverage &#xD;
of the area under consideration. There are additional techniques that enable &#xD;
refactoring. Coding standards define a common style and make it easier to refactor &#xD;
consistently. An attitude of shared code ownership within the team is important. &#xD;
Each developer should feel that refactoring can be applied across the code base &#xD;
to improve the implementation. &lt;/p>&#xD;
&lt;p> For deeper coverage on this topic, including a listing of &quot;smells&quot; and a catalog &#xD;
of refactorings to respond to them, see [&lt;a class=&quot;elementLinkWithUserText&quot; href=&quot;./../../../openup/guidances/supportingmaterials/references_6CCF393.html#FOW99&quot; guid=&quot;_9ToeIB83Edqsvps02rpOOg&quot;>FOW99&lt;/a>]. &#xD;
&lt;/p></mainDescription>
</org.eclipse.epf.uma:ContentDescription>