011-private role and use

1, with a private member variables are modified to prevent external freely modified, an error can not predict. Once the private modifier used, which are free to use this class, but outside of this class can not be used directly. If you need to modify / query is modified private member variables, can be achieved through indirect access, create a bunch of setXxx / getXxx method in this class, pay attention to the definition of setXxx / getXxx there are strict requirements. By indirect access and modification can prevent unreasonable situation, improve the robustness of the code.

Note: If the return value boolean type, use is setXxx / isXXX

Published 70 original articles · won praise 4 · Views 3974

Guess you like

Origin blog.csdn.net/l0510402015/article/details/104085972