Several modes of Java code refactoring _java

Source: Internet
Author: User

There are three main types of refactoring for Java code:

Renaming method refactoring mode, introducing explanatory variable reconstruction mode, replacing temporary variable reconstruction mode with query

Renaming Method Refactoring mode recommends performing the following steps to complete :

1. Create a method with a new name

2. Copy the method of the old method into the new method

3. The method that speaks the old method is modified to invoke the new method

4. Modify all references to the old method to refer to the new method

5. Delete old methods

The introduction of explanatory variable refactoring mode steps is relatively simple, as follows:

1. Declare a local variable and initialize it as part of the expression that needs to be replaced

2. For complex expressions, replace the parts that need to be replaced with a new local variable

3. Repeat this procedure for other parts of the expression

The steps to replace a temporary variable refactoring pattern with a query are as follows:

1. Find local variables that have been assigned only once

2. Declare the local variable final and recompile (to ensure that the variable is indeed only assigned once)

3. Copy the expression to the right of the equal sign of an assignment statement and modify it to a method body of a new method

4. Change the right of the equal sign of an assignment statement to a call to a new method

5. Replace all use of this local variable with a call to a new method

6. Delete Assignment statements and declarations for local variables

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.