封装是抽象的子集吗?
由于封装和抽象都与信息隐藏有关,我可以将封装理解为抽象的子集吗?
As both encapsulation and abstraction relate to information hiding, can I understand encapsulation as a subset of abstraction?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
封装只是实现抽象的一种方式。
“抽象”是一个概念,它是通过其本质来定义或理解特定“事物”(无论它是什么)的想法属性或行为。
“封装”是一种计算机科学技术,用于生成允许以某种方式处理具体对象的类将它们简化为抽象组件。
在计算机科学领域,其他技术(例如使用图形和其他数据结构)是为各种底层“事物”提供抽象的另一种方式,即使它们看起来可能与图形完全不同(或矩阵或其他结构)在这些结构中体现了一些基本特征。
在其他领域,抽象可以通过非常多样化的方式实现,例如人脑中永无休止的分类过程,它创建并维护代表日常概念的“原型”(高级不变表示) 。
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.
不幸的是,您上面提到的三个术语经常可以互换使用,无论好坏。
维基百科:信息隐藏
至于你的具体问题,我认为答案是否定的。封装可能不应该被视为抽象的子集。抽象或多或少是一种理想。封装
是实现良好抽象的一种手段。
Unfortunately, the three terms you mentioned above are often used somewhat interchangeably for better or for worse.
Wikipedia: Information hiding
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
is a means to achieve a good abstraction.