The sub-method handles too many situations

Source: Internet
Author: User

Refactoring code often encounters a sub-method (or Class) with complex if-else that can handle a variety of situations.

At this point the caller of the method seems simple enough to simply call the method. But in fact, all the complex logic falls to the sub-method clock.

As a result, the original non-correlated callers of the child methods also become mutually coupled. That is, I just want to modify the child method because caller a, because the child method is modified, other callers may be affected by the hash. Modification of a child method must take into account the actual usage of its various callers.

So the more the sub-method, the more it should deal with less cases. The complex logic is given to the caller for processing. Of course, if it is simply multiple state processing, such as determining whether the string address is empty in strcpy, it is easier to handle both empty and non-empty cases without affecting the difficulty of comprehension or in sub-methods.

The sub-method handles too many situations

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.