官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 天全县| 天水市| 营山县| 桂平市| 达孜县| 凌云县| 同仁县| 建湖县| 金沙县| 罗源县| 锦屏县| 泊头市| 尉氏县| 徐水县| 平潭县| 上虞市| 揭阳市| 武清区| 广平县| 利津县| 林芝县| 灵丘县| 开鲁县| 巴青县| 渝北区| 平南县| 奉化市| 石狮市| 竹溪县| 新河县| 镇坪县| 岳池县| 林口县| 托里县| 临澧县| 泊头市| 裕民县| 宁德市| 绥宁县| 盐池县| 南陵县|