Reconstruction Method 25: Change bidirectional Association to unidirectional (Change bidirectional Association to unidirectional Association)

Source: Internet
Author: User

 

2There are two-way associations between classes, but one class does not need the features of another class.Remove unnecessary associations.

Motivation: bidirectional Association is useful, but you must pay for it, that is, maintain bidirectional connections and ensure that objects are created and deleted correctly. BesidesProgramMembers are not used to bidirectional Association, which is often the source of errors.

A large number of two-way connections can easily cause "zombie objects": an object should have died, but it is still stored in the system because its reference is not completely cleared.

In addition, bidirectional Association also forces the dependency between two classes: any modifications to any of these classes may lead to changes to the other class. If these two classes are located in different assemblies, this dependency is the dependency between assemblies. Too many cross-assembly dependencies will create a tightly coupled system, so that any small changes may cause many unpredictable consequences.

it is used only when two-way association is required. If two-way association no longer has value, remove unnecessary Association.

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.