Colon and his students (serial 26)--access control

Source: Internet
Author: User
Tags modifiers

26. Access control

The husband Light Connaught will not have the letter, how easy will be more difficult--"Laozi De Sutra"

Question mark question: "Does information hiding refer specifically to using private to control access?" ”

"That's exactly our next focus. "Colon chin," access modifiers (access modifier) can be applied to the entire class in both Java and C #, in addition to class members. Public classes are naturally exposed, and the default classes are only open to the same package and assembly, respectively, in Java and C #. ”

There is no difference between commas: "What is there to pay attention to?" ”

Certainly The more basic grammar is more fastidious, the easier it is to be overlooked. "The mouth of the colon is a smile," many people are accustomed to write class when the "public class", or through the IDE automatically generate the prototype of the class, the default is generally public class. It seems harmless, but it's not a good habit. In fact, most classes do not need to be exposed, which is a higher level of information hiding. Each package or assembly, if designed reasonably, should be a collection of classes and interfaces with related functionality. Many of them are only used internally, and there is no need to be public. ”

Quote: "This is similar to object encapsulation, both to clear the interface class to the customer and to eliminate the impact of modifying the internal class on the customer." ”

The exclamation mark remains skeptical: "OOP is an encouragement and a support for reuse." It is not a pity that the classes that have been developed are deeply hidden. The client may not be able to use it for a while, but it may be used later. ”

"Good question!" This is also the psychology of most people. According to your logic, I can also say: This kind of method is not easy to develop, hidden too bad, all public! The colon vividly learned the expression and tone of the exclamation mark, and amused everyone.

Exclamation heart want to argue and mouth unspeakable.

"Reuse is exciting, reasonable reuse not only saves development time, but also saves maintenance time, and the code is more concise and beautiful." But--"colon changed," too much, excessive pursuit of reuse will cause abuse and misuse. On the one hand, developers tend to indulge in the beauty of local reuse and ignore the overall design, forget the development of the core responsibilities of the class, on the other hand, once the reuse of the class or method changes, all the users are implicated, the previous time savings may be doubled to repay. ”

Quote deep Feeling said: "The difficulty is difficult in how to grasp this degree ah!" ”

"Any technology to the advanced stage, is a ' degree ' of learning." "The colon continues to generalize," the ideal of a beginner programmer is to do whatever it wants--to solve all problems programmatically; the ideal of intermediate programmers is to do what is best--to pursue an optimal solution; the ideal of a senior programmer is to have something to do with it--the choice of a holistic design that resists the temptation of local skills. , the highest ideal is inaction and all-regardless of macro-design or micro-realization, are not deliberately selected, but natural. ”

Full Stop Heart Read a move: "These four stages can be represented by four advertising words respectively: from the world through the ' I can ', to the Olympic Games ' faster, higher, stronger ', to Anta ' I choose, I like ', and finally Martell's ' mind is different, heart has degrees '. ”

"In the end is the fashion youth, my extension to you here become the spread of the spread." "The colon is half a banter," The book goes, let's talk about it. Access modifiers for class members. ”

The colon drew a form on the blackboard--

Scope" language

C + +

Java

c#

Unrestricted

public

Public

Pu Blic

Subclass or Same package

None

Protected

P rotected internal

Same class or subclass

Protected

Private Protected (deprecated)

Protected

Same package

None

Package (default)

internal

Same class

Private (default)

Private

Private (default)

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.