封装是抽象的子集吗?

发布于 2024-08-06 21:25:36 字数 39 浏览 6 评论 0原文

由于封装和抽象都与信息隐藏有关,我可以将封装理解为抽象的子集吗?

As both encapsulation and abstraction relate to information hiding, can I understand encapsulation as a subset of abstraction?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

浮世清欢 2024-08-13 21:25:36

封装只是实现抽象的一种方式。

抽象”是一个概念,它是通过其本质来定义或理解特定“事物”(无论它是什么)的想法属性或行为。
“封装”是一种计算机科学技术,用于生成允许以某种方式处理具体对象的类将它们简化为抽象组件。

在计算机科学领域,其他技术(例如使用图形和其他数据结构)是为各种底层“事物”提供抽象的另一种方式,即使它们看起来可能与图形完全不同(或矩阵或其他结构)在这些结构中体现了一些基本特征。

在其他领域,抽象可以通过非常多样化的方式实现,例如人脑中永无休止的分类过程,它创建并维护代表日常概念的“原型”(高级不变表示) 。

Encapsulation is just one way of achieving abstraction.

'abstraction' is a concept, it is the idea of defining or understanding a particular 'thing' (whatever that may be) through its essential properties or behaviors.
'encapsulation' is a computer science technique used to produce classes which allow dealing with concrete objects in a fashion that reduces them to their abstract components.

In the domain of computer science, other techniques such as the use of graphs and other data structures are another way of providing abstraction for various underlying 'things', which even though they may not look anything like the graphs (or the matrices or other structures) have some of their essential characteristics embodied in these structures.

In other domains, abstraction can be achieved in very diverse fashion, such as the never ending classification process at work in the human brains, which creates and maintains "prototypes" (high level invariant representations) representing everyday concepts.

就像说晚安 2024-08-13 21:25:36

不幸的是,您上面提到的三个术语经常可以互换使用,无论好坏。

维基百科:信息隐藏

术语封装通常与信息隐藏互换使用。但并非所有人都同意两者之间的区别。人们可能认为信息隐藏是原理,而封装是技术。软件模块通过将信息封装到模块或其他呈现接口的构造中来隐藏信息。

至于你的具体问题,我认为答案是否定的。封装可能不应该被视为抽象的子集。抽象或多或少是一种理想。封装

划分构成其结构和行为的抽象元素的过程

是实现良好抽象的一种手段。

Unfortunately, the three terms you mentioned above are often used somewhat interchangeably for better or for worse.

Wikipedia: Information hiding

The term encapsulation is often used interchangeably with information hiding. Not all agree on the distinctions between the two though; one may think of information hiding as being the principle and encapsulation being the technique. A software module hides information by encapsulating the information into a module or other construct which presents an interface.

As to your specific question, I think the answer is no. Encapsulation is probably not best thought of as a subset of abstraction. Abstraction is more or less an ideal; encapsulation

the process of compartmentalizing the elements of an abstraction that constitute its structure and behavior

is a means to achieve a good abstraction.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文