- Mastering JavaScript Object-Oriented Programming
- Andrea Chiarelli
- 234字
- 2021-07-14 11:24:32
Encapsulation and information hiding
Encapsulation is one of the basic principles of the OOP paradigm. It allows us to bundle it into one object both data and functionalities that operate on that data.
Using the methods exposed by the object to manipulate the data, we take advantage of the encapsulation principle ignoring its internal complexity and implementation details. In other words, encapsulation hides the internal details regarding how the object manipulates its data. This feature, called the information hiding principle, is often related to encapsulation, although it is a more general principle. By hiding internal details, we obtain at least two great benefits:
- We provide a simple way to use an object, hiding the internal complexity
- We decouple the internal implementation from the use of the object, simplifying change management
The information hiding principle enforces the design of objects to have at least two parts: a public part and a private one. Only the public part is accessible by clients that want to interoperate with the object.
Many object-oriented languages, such as Java and C#, provide specific keywords such as public and private (access modifiers) to allow developers to easily implement the Information Hiding principle. JavaScript does not include such keywords. All members in an object are public by default. However, some common patterns can be used to obtain different levels of information hiding as happens in most classical OOP languages.
- Python快樂編程:人工智能深度學習基礎
- Hands-On Machine Learning with scikit:learn and Scientific Python Toolkits
- GeoServer Cookbook
- Apache Spark 2 for Beginners
- Unity Virtual Reality Projects
- MySQL 8 DBA基礎教程
- The React Workshop
- Building Mobile Applications Using Kendo UI Mobile and ASP.NET Web API
- Rust Cookbook
- MATLAB定量決策五大類問題
- 基于Swift語言的iOS App 商業實戰教程
- 低代碼平臺開發實踐:基于React
- MATLAB GUI純代碼編寫從入門到實戰
- Learning Ionic
- Learning Kotlin by building Android Applications