Art notes for modifying code

Source: Internet
Author: User

Use unit tests to simplify code modification.

 

 

Consider testing during programming: Use the class method to replace the method. In this way, you can write the inheritance class in the test to change the behavior of the corresponding method to avoid executing certain functions, better solution to dependencies.

Use header files containing preprocessing to create seams. # Ifdef testing... Endif

By modifying the contained path of the link, you can also write a class specifically used for testing. (Best, clear, and easy to maintain test code)

If the internal functions called by the function are multi-state, the internal functions are controlled through passing parameters through the base class object, and the behavior of the internal functions is controlled through the test object, instead of encapsulating the new objects inside the function.

Use the protected function instead of static and private functions to facilitate subclass.

 

Include modifications:

New method, new class

The outer method calls the original method in the new method.

Overwrite class

 

Keep the signature. The called function parameters are the same as the original ones to avoid errors.

 

Art notes for modifying code

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.