EC notes: Part 4:22. All members should be private.

Source: Internet
Author: User

EC Notes: Section 4 section: A , all members should be Private of the

More simple to access

Users don't have to remember when to take parentheses, and when not to wear braces (because they're sure to have braces)

Access restrictions

For the member variables of public, we can arbitrarily set the value (whether legal or illegal, it will be unconditionally accepted)

But if we set it to private, then we can only expose the interface, we can not only control the access of the members (read-write, read-only, write-only, forbidden access), but also can check the incoming values, specify which values can be set, which is not.

Easier to maintain

We set the members to public, and if one day we find that this variable is not set up reasonably (it may be necessary to change its name or type), we must make modifications to each user code that uses this member variable.

And if we just expose the interface, we can modify it directly inside the tired, as long as the access interface remains the same.

EC notes: Part 4:22. All members should be private.

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.