Bad code 17: Inappropriate intimacy)

Source: Internet
Author: User

sometimes you will see 2 classes are too close, spend too much time exploring each other's private components. You can use move method (shift function) and move field (moving fields) helps them draw a line. You can also see if you can use change bidirectional Association to unidirectional (Change bidirectional Association to unidirectional Association) disconnects one class from the other. If the 2 classes are really intended, you can use extract class (refining class) extract 2 people in common to a safe place, so that they can use this new class openly. Alternatively, you can use hide DeleGate to hide the delegate relationship) let another class share their thoughts.

Inheritance often leads to excessive intimacy, because subclass's understanding of superclasses always exceeds the latter's subjective desire. If you think it is time to let the child live alone, please useReplace inheritance with Delegation(Replace inheritance with delegation)Let it leave the inheritance relationship.

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.