
上QQ阅读APP看书,第一时间看更新
Encapsulation
Simply put, this means that the inner workings of the class (the implementation details) are not necessarily shared with outside code. Remember that we mentioned earlier that a class is something that you just want to use and expect it to work. The class exposes what it needs to to the calling code, but it maintains tight control over the inner workings it implements.
You can, therefore, hide the variables, properties, and methods by scoping them as private. This way, you protect the data contained inside the class from accidental corruption.