Reconstruction Method 43: Add parameter (add parameter)

Source: Internet
Author: User

A function needs to obtain more information from the caller.Add an object parameter to this function to bring the object into the required information of the function.

Motivation: Add parameter is a common refactoring technique. The motivation for using this refactoring is simple: you must modify a function, and the modified function requires information that is not available in the past. Therefore, you need to add a parameter to the function.

It should be noted that the timing of this reconstruction is not used. In addition to adding parameters, you often have other options. If possible, other options are better than adding parameters because they do not increase the length of the parameter column. Too long parameter columns are bad becauseProgramIt is hard for a Member to remember so many parameters and long parameter columns are often accompanied by bad taste: Data clumps ).

Take a look at the existing parameters and ask yourself: Can you get the required information from these parameters? If the answer is no, is it possible to provide the required information through a function? Where do you actually use this information? Should this function belong to the object with this information? Take a look at the existing parameters. Is it appropriate to add new parameters? Maybe you should consider using introduce parameter object (introducing the parameter object ).

Method: 1. Check whether the function signature has been implemented by a superclass or subclass. If yes, perform the following steps for each implementation.

2Declare a new function with the same name as the original function, but add new parameters. ConvertCodeCopy to the new function.

3, Compile.

4Modify the old function to call the new function.

5, Compilation, and testing.

6Find all reference points of the function. Modify all of them to reference the new function. After each modification, compile the test.

7And delete old functions.

8, Compilation, and testing.

 

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.