封装与数据隐藏?(Encapsulation Vs DataHiding?)

系统教程 行业动态 更新时间:2024-06-14 16:57:40
封装与数据隐藏?(Encapsulation Vs DataHiding?)

这可能是重复的问题,但我还没有找到答案。

链接1

封装:

封装是将类中的字段私有化并通过公共方法提供对字段的访问的技术。 如果一个字段被声明为私有的,它不能被类之外的任何人访问, 从而隐藏该类中的字段。 出于这个原因,封装也被称为数据隐藏

链接2

封装:

“它指的是在一些概念性障碍的情况下围绕一些东西收集胶囊。” - [Wirfs-Brock等,1990]

“作为一个过程,封装意味着将一个或多个物品封装在一个容器内。封装作为一个实体,指的是一个包装或一个容纳(包含,封装)一个或多个物品的外壳。”

“如果封装与信息隐藏一样”,那么人们可能会说“封装的所有东西都隐藏了”。 这显然不是真的。“

我应该去哪一个? 还是我误解了这个定义?

This might be the duplicate question but I haven't found the answer yet.

Link 1

Encapsulation:

Encapsulation is the technique of making the fields in a class private and providing access to the fields via public methods. If a field is declared private, it cannot be accessed by anyone outside the class, thereby hiding the fields within the class. For this reason, encapsulation is also referred to as data hiding

Link 2

Encapsulation:

"It […] refers to building a capsule, in the case a conceptual barrier, around some collection of things." — [Wirfs-Brock et al, 1990]

"As a process, encapsulation means the act of enclosing one or more items within a […] container. Encapsulation, as an entity, refers to a package or an enclosure that holds (contains, encloses) one or more items."

"If encapsulation was 'the same thing as information hiding,' then one might make the argument that 'everything that was encapsulated was also hidden.' This is not obviously not true."

Which one should I go with ? Or have I misunderstood the definition ?

最满意答案

重点是它并不重要。 任何人都可以用一种稍微不同的方式来定义一个术语,并且通常各种作者都会根据他们使用这些术语的各种环境来调整意义。

试图找出哪一个是“正确的”,哪一个是“错误的”,你不会得到启发。 从上下文中引用的行情特别没有意义。

重要的是要理解底层的想法,而不用参考用来引用它们的词汇表。

The main point is that it doesn't really matter. Anyone can define a term in a slightly different way, and usually various authors adapt the meaning to the various contexts within which they use those terms.

You will not gain any enlightenment from trying to figure out which one is "right" and which one is "wrong". Quotes taken out of context are especially uninformative.

The important thing is to understand the underlying ideas without reference to the vocabulary items used to refer to them.

更多推荐

本文发布于:2023-04-13 12:23:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/44b978d5326368891d6fe99ee188a50a.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据   Encapsulation   DataHiding

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!