抽象 VS 信息隐藏 VS 封装 [英] Abstraction VS Information Hiding VS Encapsulation

查看:32
本文介绍了抽象 VS 信息隐藏 VS 封装的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你能告诉我软件开发中抽象信息隐藏有什么区别吗?

Can you tell me what is the difference between abstraction and information hiding in software development?

我很困惑.抽象隐藏了细节实现和信息隐藏抽象了事物的全部细节.

I am confused. Abstraction hides detail implementation and information hiding abstracts whole details of something.

更新:我为这三个概念找到了一个很好的答案.请参阅下面的单独答案,以获取从 那里.

Update: I found a good answer for these three concepts. See the separate answer below for several citations taken from there.

推荐答案

去源码!Grady Booch 说(在面向对象的分析和设计中,第 49 页,第二版):

Go to the source! Grady Booch says (in Object Oriented Analysis and Design, page 49, second edition):

抽象和封装是互补的概念:抽象关注对象的可观察行为...封装专注于导致这种行为的实现......封装通常是通过信息隐藏来实现的,即是隐藏对象的所有秘密的过程有助于其基本特征.

Abstraction and encapsulation are complementary concepts: abstraction focuses on the observable behavior of an object... encapsulation focuses upon the implementation that gives rise to this behavior... encapsulation is most often achieved through information hiding, which is the process of hiding all of the secrets of object that do not contribute to its essential characteristics.

换句话说:抽象=外部的对象;封装(通过信息隐藏实现)=对象内部,

In other words: abstraction = the object externally; encapsulation (achieved through information hiding) = the object internally,

示例:在 .NET Framework 中,System.Text.StringBuilder 类提供了对字符串缓冲区的抽象.此缓冲区抽象使您可以在不考虑其实现的情况下使用缓冲区.因此,您可以将字符串附加到缓冲区,而无需考虑 StringBuilder 在内部如何跟踪诸如指向缓冲区的指针和缓冲区满时管理内存(它通过封装来实现)通过信息隐藏).

Example: In the .NET Framework, the System.Text.StringBuilder class provides an abstraction over a string buffer. This buffer abstraction lets you work with the buffer without regard for its implementation. Thus, you're able to append strings to the buffer without regard for how the StringBuilder internally keeps track of things such the pointer to the buffer and managing memory when the buffer gets full (which it does with encapsulation via information hiding).

rp

这篇关于抽象 VS 信息隐藏 VS 封装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆