Effective C + + clause 23 Ning replace member function with Non-member,non-friend

Source: Internet
Author: User

1. The true meaning of object-oriented is not that the functions of data and manipulating data should be bundled together, but that data should be encapsulated as much as possible. Encapsulation means that the data is invisible, the more things are encapsulated, the less direct user contact is, the lower the user code and the compiled correlation of the encapsulated content, the "wrap elasticity" The higher it is, the better the encapsulation, the lower the impact on the code changes.

2. The Non-member-non-friend function is actually higher than the public-member and friend functions, because the former cannot access the private object of the class, while the latter can access any object of the class, which obviously reduces the encapsulation of the data (of course, The non-member of a function into a class for encapsulation reasons does not mean that it cannot be a member of other classes.

3. If there is no compilation dependency between the Non-member functions, you can separate them by declaring them in a different header file in the same namespace. Placing functions in multiple header files but belonging to the same namespace allows customers to easily extend this set of functions, Just add more non-member-non-friend to the same namespace. But the member function is not possible, because the class must be defined as a whole and cannot be segmented into fragment segments, so in terms of "functional extensibility", The Non-member-non-friend function is also due to the member function.

Effective C + + clause 23 Ning replace member function with Non-member,non-friend

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.