Bad code taste 06: Shotgun surgery)

Source: Internet
Author: User

Shotgun surgery is similar to divergent change. If you encounter a change, you must make many small changes in many different classes. The bad thing you face is shotgun surgery ). If you want to modifyCodeIt is difficult for you to find them and easily forget an important modification.

You can use the move method and move field to put all the code to be modified into the same class. If no suitable class exists, create one. Generally, you can use inline class to put a series of related behaviors into the same class. This may cause a small amount of divergent changes, but it is easy to come out.

Divergent change refers to "one class is affected by multiple changes", and shotgun surgery refers to "one change causes multiple class modifications ". In both cases, you may want to organize the code to make the "external changes" and "classes to be modified" one by one.

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.