抽象VS信息隐藏VS封装

时间:2022-09-02 09:31:14

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.

更新:我找到了这三个概念的好答案。请参阅下面单独的答案,从中获取几个引用。

20 个解决方案

#1


146  

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

去源头! Grady Booch说(面向对象分析与设计,第49页,第二版):

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,

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

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).

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

rp

#2


72  

The OP updated his question with several citations that he had found, namely in an article by Edward V. Berard titled, "Abstraction, Encapsulation, and Information Hiding". I am re-posting a slightly expanded and reformatted version of the OP's update, since it should be an answer in its own right.

OP通过他发现的几个引用更新了他的问题,即Edward V. Berard撰写的题为“抽象,封装和信息隐藏”的文章。我正在重新发布一个稍微扩展和重新格式化的OP更新版本,因为它本身应该是一个答案。

(All citations are taken from the article mentioned above.)

(所有引文均来自上述文章。)

Abstraction:

"One point of confusion regarding abstraction is its use as both process and an entity. Abstraction, as a process, denotes the extracting of the essential details about an item, or a group of items, while ignoring the inessential details. Abstraction, as an entity, denotes a model, a view, or some other focused representation for an actual item."

“关于抽象的一个混淆点是它作为一个过程和一个实体的使用。抽象,作为一个过程,表示提取关于一个项目或一组项目的基本细节,而忽略了不必要的细节。抽象,作为一个实体,表示实际项目的模型,视图或其他一些集中表示。“

Information Hiding:

"Its interface or definition was chosen to reveal as little as possible about its inner workings." — [Parnas, 1972b]

“它的界面或定义被选中以尽可能少地揭示它的内部运作。” - [Parnas,1972b]

"Abstraction can be […] used as a technique for identifying which information should be hidden."

“抽象可以用作识别应隐藏哪些信息的技术。”

"Confusion can occur when people fail to distinguish between the hiding of information, and a technique (e.g., abstraction) that is used to help identify which information is to be hidden."

“当人们无法区分隐藏信息和用于帮助识别哪些信息被隐藏的技术(例如,抽象)时,就会发生混淆。”

Encapsulation:

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

“它[...]指的是围绕一些东西建造一个胶囊,在一个概念障碍的情况下。” - [Wirfs-Brock等,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 obviously not true."

“如果封装与信息隐藏相同,那么人们可能会认为'封装的所有内容也都是隐藏的'。这显然不是真的。“

Conclusion:

"Abstraction, information hiding, and encapsulation are very different, but highly-related, concepts. One could argue that abstraction is a technique that help us identify which specific information should be visible, and which information should be hidden. Encapsulation is then the technique for packaging the information in such a way as to hide what should be hidden, and make visible what is intended to be visible."

“抽象,信息隐藏和封装是非常不同的,但是高度相关的概念。人们可以争辩说,抽象是一种技术,可以帮助我们识别哪些特定信息应该是可见的,哪些信息应该被隐藏。然后,封装是技术用于包装信息的方式,以隐藏应隐藏的内容,并使可见的内容可见。“

#3


45  

Abstraction is hiding the implementation details by providing a layer over the basic functionality.

抽象通过提供基本功能层来隐藏实现细节。

Information Hiding is hiding the data which is being affected by that implementation. Use of private and public comes under this. For example, hiding the variables of the classes.

信息隐藏是隐藏受该实现影响的数据。在此范围内使用私人和公共。例如,隐藏类的变量。

Encapsulation is just grouping all similar data and functions into a group e.g Class in programming; Packet in networking.

封装只是将所有类似的数据和功能分组到一个组中,例如编程中的类;网络中的数据包。

Through the use of Classes, we implement all three concepts - Abstraction, Information Hiding and Encapsulation

通过使用类,我们实现了所有三个概念 - 抽象,信息隐藏和封装

#4


29  

Please don't complicate simple concepts.

请不要简单概念复杂化。

Encapsulation : Wrapping up of data and methods into a single unit is Encapsulation (e.g. Class)

封装:将数据和方法包装到单个单元中是封装(例如,类)

Abstraction : It is an act of representing only the essential things without including background details. (e.g. Interface)

抽象:这是一种仅包含基本事物而不包括背景细节的行为。 (例如界面)

FOR EXAMPLES AND MORE INFO GOTO :

例子和更多信息GOTO:

http://thecodekey.com/C_VB_Codes/Encapsulation.aspx

http://thecodekey.com/C_VB_Codes/Abstraction.aspx

Approved definitions here

这里批准了定义

P.S.: I also remember the definition from a book named C++ by Sumita Arora which we read in 11th class ;)

P.S。:我还记得Sumita Arora的一本名为C ++的书的定义,我们在第11课阅读了这本书;)

#5


6  

The meaning of abstraction given by the Oxford English Dictionary (OED) closest to the meaning intended here is 'The act of separating in thought'. A better definition might be 'Representing the essential features of something without including background or inessential detail.'

牛津英语词典(OED)给出的最接近这里意思的抽象意义是“思想中的分离行为”。一个更好的定义可能是“代表某些东西的基本特征,而不包括背景或不必要的细节。”

Information hiding is the principle that users of a software component (such as a class) need to know only the essential details of how to initialize and access the component, and do not need to know the details of the implementation.

信息隐藏是软件组件(例如类)的用户仅需要知道如何初始化和访问组件的基本细节的原则,并且不需要知道实现的细节。

Edit: I seems to me that abstraction is the process of deciding which parts of the implementation that should be hidden.

编辑:在我看来,抽象是决定应该隐藏的实现的哪些部分的过程。

So its not abstraction VERSUS information hiding. It's information hiding VIA abstraction.

所以它不是抽象的VERSUS信息隐藏。这是隐藏VIA抽象的信息。

#6


4  

Abstraction

Abstraction is an act of representing essentail details without including the background details. A abstract class have only method signatures and implementing class can have its own implementation, in this way the complex details will be hidden from the user. Abstraction focuses on the outside view. In otherwords, Abstraction is sepration of interfaces from the actual implementation.

抽象是表示essentail细节而不包括背景细节的行为。抽象类只有方法签名,实现类可以有自己的实现,这样复杂的细节就会对用户隐藏。抽象侧重于外部视图。换句话说,抽象是从实际实现中分离接口。

Encapsulation

Encapsulation explains binding the data members and methods into a single unit. Information hiding is the main purpose of encapsulation. Encapsulation is acheived by using access specifiers like private, public, protected. Class member variables are made private so that they cann't be accessible directly to outside world. Encapsulation focuses on the inner view. In otherwords, Encapsulation is a technique used to protect the information in an object from the other object.

封装解释了将数据成员和方法绑定到单个单元中。信息隐藏是封装的主要目的。通过使用私有,公共,受保护等访问说明符来实现封装。类成员变量是私有的,因此无法直接访问外部世界。封装侧重于内部视图。换句话说,封装是一种用于保护对象中的信息不受其他对象影响的技术。

#7


3  

Abstraction is hiding details of implementation as you put it.

正如你所说,抽象隐藏了实现的细节。

You abstract something to a high enough point that you'll only have to do something very simple to perform an action.

你抽象的东西足够高,你只需要做一些非常简单的事情来执行一个动作。

Information hiding is hiding implementation details. Programming is hard. You can have a lot of things to deal with and handle. There can be variables you want/need to keep very close track of. Hiding information ensures that no one accidentally breaks something by using a variable or method you exposed publicly.

信息隐藏隐藏了实现细节。编程很难。你可以有很多事情需要处理和处理。您可能需要/需要保持非常接近的变量。隐藏信息可确保没有人通过使用您公开公开的变量或方法意外破坏某些内容。

These 2 concepts are very closely tied together in object-oriented programming.

这两个概念在面向对象的编程中非常紧密地联系在一起。

#8


2  

Encapsulation: binding the data members and member functions together is called encapsulation. encapsulation is done through class. abstraction: hiding the implementation details form usage or from view is called abstraction. ex: int x; we don't know how int will internally work. but we know int will work. that is abstraction.

封装:将数据成员和成员函数绑定在一起称为封装。封装是通过类完成的。抽象:隐藏实现细节表单用法或从视图中称为抽象。 ex:int x;我们不知道int将如何在内部工作。但我们知道int会起作用。那就是抽象。

#9


2  

Abstraction - It is the process of identifying the essential characteristics of an object without including the irrelevant and tedious details.

抽象 - 这是识别对象的基本特征而不包括无关和繁琐细节的过程。

Encapsulation - It is the process of enclosing data and functions manipulating this data into a single unit.

封装 - 将数据和函数封装到一个单元中的过程。

Abstraction and Encapsulation are related but complementary concepts.

抽象和封装是相关但互补的概念。

  1. Abstraction is the process. Encapsulation is the mechanism by which Abstraction is implemented.

    抽象就是这个过程。封装是实现抽象的机制。

  2. Abstraction focuses on the observable behavior of an object. Encapsulation focuses upon the implementation that give rise to this behavior.

    抽象侧重于对象的可观察行为。封装侧重于导致此行为的实现。

Information Hiding - It is the process of hiding the implementation details of an object. It is a result of Encapsulation.

信息隐藏 - 隐藏对象的实现细节的过程。这是Encapsulation的结果。

#10


2  

Abstraction : Abstraction is the concept/technique used to identify what should be the external view of an object. Making only the required interface available.

抽象:抽象是用于识别对象的外部视图的概念/技术。仅提供所需的界面。

Information Hiding : It is complementary to Abstraction, as through information hiding Abstraction is achieved. Hiding everything else but the external view.

信息隐藏:它是对抽象的补充,因为通过信息隐藏抽象实现。隐藏除了外部视图之外的所有其他内容。

Encapsulation : Is binding of data and related functions into a unit. It facilitates Abstraction and information hiding. Allowing features like member access to be applied on the unit to achieve Abstraction and Information hiding

封装:将数据和相关功能绑定到一个单元中。它有助于抽象和信息隐藏。允许在单元上应用成员访问等功能以实现抽象和信息隐藏

#11


2  

See Joel's post on the Law of Leaky Abstractions

请参阅Joel关于漏洞抽象法的文章

JoelOnsoftware

Basically, abstracting gives you the freedom of thinking of higher level concepts. A non-programming analogy is that most of us do not know where our food comes from, or how it is produced, but the fact that we (usually) don't have to worry about it frees us up to do other things, like programming.

基本上,抽象可以让您*地思考更高层次的概念。一个非编程的类比是,我们大多数人都不知道我们的食物来自何处,或者它是如何产生的,但我们(通常)不必担心它会使我们*地做其他事情,比如节目。

As for information hiding, I agree with jamting.

至于信息隐藏,我同意干扰。

#12


1  

Abstraction allows you to treat a complex process as a simple process. For example, the standard "file" abstraction treats files as a contiguous array of bytes. The user/developer does not even have to think about issues of clusters and fragmentation. (Abstraction normally appears as classes or subroutines.)

抽象允许您将复杂过程视为一个简单过程。例如,标准“文件”抽象将文件视为连续的字节数组。用户/开发人员甚至不必考虑集群和碎片问题。 (抽象通常表现为类或子例程。)

Information hiding is about protecting your abstractions from malicious/incompetent users. By restricting control of some state (hard drive allocations, for example) to the original developer, huge amounts of error handling becomes redundant. If nobody else besides the file system driver can write to the hard drive, then the file system driver knows exactly what has been written to the hard drive and where. (The usual manifestation of this concept is private and protected keywords in OO languages.)

信息隐藏是为了保护您的抽象免受恶意/无能用户的侵害。通过将某些状态(例如硬盘驱动器分配)的控制限制为原始开发人员,大量的错误处理变得多余。如果除了文件系统驱动程序之外没有其他人可以写入硬盘驱动器,则文件系统驱动程序确切地知道已写入硬盘驱动器的位置以及位置。 (这个概念的通常表现形式是OO语言中的私有和受保护的关键字。)

#13


1  

To abstract something we need to hide the detail or to hide the detail of something we need to abstract it. But, both of them can be achieved by encapsulation.

要抽象一些东西,我们需要隐藏细节或隐藏我们需要抽象它的细节。但是,它们都可以通过封装来实现。

So, information hiding is a goal, abstraction is a process, and encapsulation is a technique.

因此,信息隐藏是一个目标,抽象是一个过程,封装是一种技术。

#14


1  

Abstraction simply means the technique in which only essential details of software is made visible to the user to help the user to use or operate with software, thus implementation details of that software are not shown(are made invisible). Encapsulation is the technique that have package that hold one or more items and hence some of information (particularly program details) became visible and some not visible to the user, so encapsulation is achieved through information hiding. In summary. Abstraction is for observable behavior (externally) and encapsulation is for invisibility (internally) but these two are really complementary.

抽象仅仅意味着这样一种技术,其中只有软件的基本细节对用户可见,以帮助用户使用或操作软件,因此不显示该软件的实现细节(使其不可见)。封装是具有包含一个或多个项目的包的技术,因此一些信息(特别是程序细节)变得可见并且一些对用户不可见,因此封装是通过信息隐藏来实现的。综上所述。抽象是为了可观察行为(外部),封装是为了隐形(内部),但这两者是真正互补的。

#15


1  

Just adding on more details around InformationHiding, found This link is really good source with examples

只是添加有关InformationHiding的更多详细信息,发现这个链接非常好,带有示例

InformationHiding is the idea that a design decision should be hidden from the rest of the system to prevent unintended coupling. InformationHiding is a design principle. InformationHiding should inform the way you encapsulate things, but of course it doesn't have to.

信息隐藏的想法是,应该从系统的其余部分隐藏设计决策,以防止意外耦合。信息隐藏是一种设计原则。 InformationHiding应该告知你封装事物的方式,当然它不需要。

Encapsulation is a programming language feature.

封装是一种编程语言功能。

#16


1  

I too was very confused about the two concepts of Abstraction and Encapsulation. But when I saw the abstraction article on myjavatrainer.com, It became clear to me that Abstraction and Encapsulation are Apples and Oranges, you can't really compare them because both are required.

我也对抽象和封装这两个概念感到非常困惑。但是当我在myjavatrainer.com上看到抽象文章时,我清楚地知道抽象和封装是苹果和橘子,你无法真正比​​较它们,因为两者都是必需的。

Encapsulation is how the object is created, and abstraction is how the object is viewed in the outside world.

封装是对象的创建方式,抽象是对象在外部世界中的查看方式。

#17


0  

After reading all the above answers one by one I cant stop myself from posting that

在逐一阅读上述所有答案后,我无法阻止自己发布

abstraction involves the facility to define objects that represent abstract "actors" that can perform work, report on and change their state, and "communicate" with other objects in the system.

抽象涉及定义表示抽象“actor”的对象的工具,这些对象可以执行工作,报告和更改其状态,并与系统中的其他对象“通信”。

Encapsulation is quite clear from above however ->

然而,封装从上面可以清楚地看出 - >

The term encapsulation refers to the hiding of state details, but extending the concept of data type from earlier programming languages to associate behavior most strongly with the data, and standardizing the way that different data types interact, is the beginning of abstraction.

术语封装是指隐藏状态细节,但是从早期编程语言扩展数据类型的概念,以最强烈地将行为与数据相关联,并标准化不同数据类型交互的方式,是抽象的开始。

reference wiki

#18


0  

Encapsulation: binding data and the methods that act on it. this allows the hiding of data from all other methods in other classes. example: MyList class that can add an item, remove an item, and remove all items the methods add, remove, and removeAll act on the list(a private array) that can not be accessed directly from the outside.

封装:绑定数据和作用于它的方法。这允许隐藏其他类中的所有其他方法的数据。示例:MyList类可以添加项目,删除项目,并删除方法添加,删除和删除所有项目列表(私有阵列)上无法直接从外部访问的所有项目。

Abstraction: is hiding the non relevant behavior and data. How the items are actually stored, added, or deleted is hidden (abstracted). My data may be held in simple array, ArrayList, LinkedList, and so on. Also, how the methods are implemented is hidden from the outside.

抽象:隐藏不相关的行为和数据。如何实际存储,添加或删除项目是隐藏的(抽象的)。我的数据可以保存在简单数组,ArrayList,LinkedList等中。此外,如何实现这些方法是从外部隐藏的。

#19


0  

Encapsulation- enforcing access to the internal data in a controlled manner or preventing members from being accessed directly.

封装 - 以受控方式强制访问内部数据或阻止成员直接访问。

Abstraction- Hiding the implementation details of certain methods is known as abstraction

抽象 - 隐藏某些方法的实现细节称为抽象

Let's understand with the help of an example:-

让我们借助一个例子来理解: -

class Rectangle
{
private int length;
private int breadth;// see the word private that means they cant be accesed from 
outside world.
 //now to make them accessed indirectly define getters and setters methods
void setLength(int length)
{  
// we are adding this condition to prevent users to make any irrelevent changes 
  that is why we have made length private so that they should be set according to 
   certain restrictions
if(length!=0)
{
 this.length=length
 }
void getLength()
{
 return length;
 }
 // same do for breadth
}

now for abstraction define a method that can only be accessed and user doesnt know what is the body of the method and how it is working Let's consider the above example, we can define a method area which calculates the area of the rectangle.

现在用于抽象定义一个只能访问的方法,用户不知道方法的主体是什么以及它是如何工作的让我们考虑上面的例子,我们可以定义一个计算矩形区域的方法区域。

 public int area()
 {
  return length*breadth;
 }

Now, whenever a user uses the above method he will just get the area not the way how it is calculated. We can consider an example of println() method we just know that it is used for printing and we don't know how it prints the data. I have written a blog in detail you can see the below link for more info abstraction vs encapsulation

现在,每当用户使用上述方法时,他将获得的区域不是计算方式。我们可以考虑println()方法的一个例子,我们只知道它用于打印,我们不知道它是如何打印数据的。我已经写了一篇详细的博客,你可以看到下面的链接,了解更多信息抽象与封装

#20


0  

It's worth noting these terms have standardized, IEEE definitions, which can be searched at https://pascal.computer.org/.

值得注意的是,这些术语具有标准化的IEEE定义,可以在https://pascal.computer.org/上进行搜索。

abstraction

  1. view of an object that focuses on the information relevant to a particular purpose and ignores the remainder of the information
  2. 一个对象的视图,该对象侧重于与特定目的相关的信息,并忽略其余信息

  3. process of formulating a view
  4. 制定观点的过程

  5. process of suppressing irrelevant detail to establish a simplified model, or the result of that process
  6. 抑制不相关细节以建立简化模型或该过程结果的过程

information hiding

  1. software development technique in which each module's interfaces reveal as little as possible about the module's inner workings and other modules are prevented from using information about the module that is not in the module's interface specification
  2. 软件开发技术,其中每个模块的接口尽可能少地揭示模块的内部工作和其他模块被阻止使用有关模块的信息不在模块的接口规范中

  3. containment of a design or implementation decision in a single module so that the decision is hidden from other modules
  4. 在单个模块中包含设计或实现决策,以便从其他模块中隐藏决策

encapsulation

  1. software development technique that consists of isolating a system function or a set of data and operations on those data within a module and providing precise specifications for the module
  2. 软件开发技术,包括在模块内隔离系统功能或一组数据和操作,并为模块提供精确的规范

  3. concept that access to the names, meanings, and values of the responsibilities of a class is entirely separated from access to their realization
  4. 这样一种概念,即对类的职责的名称,含义和价值的访问与对其实现的访问完全分开

  5. idea that a module has an outside that is distinct from its inside, that it has an external interface and an internal implementation
  6. 认为模块具有与其内部不同的外部,它具有外部接口和内部实现

#1


146  

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

去源头! Grady Booch说(面向对象分析与设计,第49页,第二版):

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,

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

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).

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

rp

#2


72  

The OP updated his question with several citations that he had found, namely in an article by Edward V. Berard titled, "Abstraction, Encapsulation, and Information Hiding". I am re-posting a slightly expanded and reformatted version of the OP's update, since it should be an answer in its own right.

OP通过他发现的几个引用更新了他的问题,即Edward V. Berard撰写的题为“抽象,封装和信息隐藏”的文章。我正在重新发布一个稍微扩展和重新格式化的OP更新版本,因为它本身应该是一个答案。

(All citations are taken from the article mentioned above.)

(所有引文均来自上述文章。)

Abstraction:

"One point of confusion regarding abstraction is its use as both process and an entity. Abstraction, as a process, denotes the extracting of the essential details about an item, or a group of items, while ignoring the inessential details. Abstraction, as an entity, denotes a model, a view, or some other focused representation for an actual item."

“关于抽象的一个混淆点是它作为一个过程和一个实体的使用。抽象,作为一个过程,表示提取关于一个项目或一组项目的基本细节,而忽略了不必要的细节。抽象,作为一个实体,表示实际项目的模型,视图或其他一些集中表示。“

Information Hiding:

"Its interface or definition was chosen to reveal as little as possible about its inner workings." — [Parnas, 1972b]

“它的界面或定义被选中以尽可能少地揭示它的内部运作。” - [Parnas,1972b]

"Abstraction can be […] used as a technique for identifying which information should be hidden."

“抽象可以用作识别应隐藏哪些信息的技术。”

"Confusion can occur when people fail to distinguish between the hiding of information, and a technique (e.g., abstraction) that is used to help identify which information is to be hidden."

“当人们无法区分隐藏信息和用于帮助识别哪些信息被隐藏的技术(例如,抽象)时,就会发生混淆。”

Encapsulation:

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

“它[...]指的是围绕一些东西建造一个胶囊,在一个概念障碍的情况下。” - [Wirfs-Brock等,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 obviously not true."

“如果封装与信息隐藏相同,那么人们可能会认为'封装的所有内容也都是隐藏的'。这显然不是真的。“

Conclusion:

"Abstraction, information hiding, and encapsulation are very different, but highly-related, concepts. One could argue that abstraction is a technique that help us identify which specific information should be visible, and which information should be hidden. Encapsulation is then the technique for packaging the information in such a way as to hide what should be hidden, and make visible what is intended to be visible."

“抽象,信息隐藏和封装是非常不同的,但是高度相关的概念。人们可以争辩说,抽象是一种技术,可以帮助我们识别哪些特定信息应该是可见的,哪些信息应该被隐藏。然后,封装是技术用于包装信息的方式,以隐藏应隐藏的内容,并使可见的内容可见。“

#3


45  

Abstraction is hiding the implementation details by providing a layer over the basic functionality.

抽象通过提供基本功能层来隐藏实现细节。

Information Hiding is hiding the data which is being affected by that implementation. Use of private and public comes under this. For example, hiding the variables of the classes.

信息隐藏是隐藏受该实现影响的数据。在此范围内使用私人和公共。例如,隐藏类的变量。

Encapsulation is just grouping all similar data and functions into a group e.g Class in programming; Packet in networking.

封装只是将所有类似的数据和功能分组到一个组中,例如编程中的类;网络中的数据包。

Through the use of Classes, we implement all three concepts - Abstraction, Information Hiding and Encapsulation

通过使用类,我们实现了所有三个概念 - 抽象,信息隐藏和封装

#4


29  

Please don't complicate simple concepts.

请不要简单概念复杂化。

Encapsulation : Wrapping up of data and methods into a single unit is Encapsulation (e.g. Class)

封装:将数据和方法包装到单个单元中是封装(例如,类)

Abstraction : It is an act of representing only the essential things without including background details. (e.g. Interface)

抽象:这是一种仅包含基本事物而不包括背景细节的行为。 (例如界面)

FOR EXAMPLES AND MORE INFO GOTO :

例子和更多信息GOTO:

http://thecodekey.com/C_VB_Codes/Encapsulation.aspx

http://thecodekey.com/C_VB_Codes/Abstraction.aspx

Approved definitions here

这里批准了定义

P.S.: I also remember the definition from a book named C++ by Sumita Arora which we read in 11th class ;)

P.S。:我还记得Sumita Arora的一本名为C ++的书的定义,我们在第11课阅读了这本书;)

#5


6  

The meaning of abstraction given by the Oxford English Dictionary (OED) closest to the meaning intended here is 'The act of separating in thought'. A better definition might be 'Representing the essential features of something without including background or inessential detail.'

牛津英语词典(OED)给出的最接近这里意思的抽象意义是“思想中的分离行为”。一个更好的定义可能是“代表某些东西的基本特征,而不包括背景或不必要的细节。”

Information hiding is the principle that users of a software component (such as a class) need to know only the essential details of how to initialize and access the component, and do not need to know the details of the implementation.

信息隐藏是软件组件(例如类)的用户仅需要知道如何初始化和访问组件的基本细节的原则,并且不需要知道实现的细节。

Edit: I seems to me that abstraction is the process of deciding which parts of the implementation that should be hidden.

编辑:在我看来,抽象是决定应该隐藏的实现的哪些部分的过程。

So its not abstraction VERSUS information hiding. It's information hiding VIA abstraction.

所以它不是抽象的VERSUS信息隐藏。这是隐藏VIA抽象的信息。

#6


4  

Abstraction

Abstraction is an act of representing essentail details without including the background details. A abstract class have only method signatures and implementing class can have its own implementation, in this way the complex details will be hidden from the user. Abstraction focuses on the outside view. In otherwords, Abstraction is sepration of interfaces from the actual implementation.

抽象是表示essentail细节而不包括背景细节的行为。抽象类只有方法签名,实现类可以有自己的实现,这样复杂的细节就会对用户隐藏。抽象侧重于外部视图。换句话说,抽象是从实际实现中分离接口。

Encapsulation

Encapsulation explains binding the data members and methods into a single unit. Information hiding is the main purpose of encapsulation. Encapsulation is acheived by using access specifiers like private, public, protected. Class member variables are made private so that they cann't be accessible directly to outside world. Encapsulation focuses on the inner view. In otherwords, Encapsulation is a technique used to protect the information in an object from the other object.

封装解释了将数据成员和方法绑定到单个单元中。信息隐藏是封装的主要目的。通过使用私有,公共,受保护等访问说明符来实现封装。类成员变量是私有的,因此无法直接访问外部世界。封装侧重于内部视图。换句话说,封装是一种用于保护对象中的信息不受其他对象影响的技术。

#7


3  

Abstraction is hiding details of implementation as you put it.

正如你所说,抽象隐藏了实现的细节。

You abstract something to a high enough point that you'll only have to do something very simple to perform an action.

你抽象的东西足够高,你只需要做一些非常简单的事情来执行一个动作。

Information hiding is hiding implementation details. Programming is hard. You can have a lot of things to deal with and handle. There can be variables you want/need to keep very close track of. Hiding information ensures that no one accidentally breaks something by using a variable or method you exposed publicly.

信息隐藏隐藏了实现细节。编程很难。你可以有很多事情需要处理和处理。您可能需要/需要保持非常接近的变量。隐藏信息可确保没有人通过使用您公开公开的变量或方法意外破坏某些内容。

These 2 concepts are very closely tied together in object-oriented programming.

这两个概念在面向对象的编程中非常紧密地联系在一起。

#8


2  

Encapsulation: binding the data members and member functions together is called encapsulation. encapsulation is done through class. abstraction: hiding the implementation details form usage or from view is called abstraction. ex: int x; we don't know how int will internally work. but we know int will work. that is abstraction.

封装:将数据成员和成员函数绑定在一起称为封装。封装是通过类完成的。抽象:隐藏实现细节表单用法或从视图中称为抽象。 ex:int x;我们不知道int将如何在内部工作。但我们知道int会起作用。那就是抽象。

#9


2  

Abstraction - It is the process of identifying the essential characteristics of an object without including the irrelevant and tedious details.

抽象 - 这是识别对象的基本特征而不包括无关和繁琐细节的过程。

Encapsulation - It is the process of enclosing data and functions manipulating this data into a single unit.

封装 - 将数据和函数封装到一个单元中的过程。

Abstraction and Encapsulation are related but complementary concepts.

抽象和封装是相关但互补的概念。

  1. Abstraction is the process. Encapsulation is the mechanism by which Abstraction is implemented.

    抽象就是这个过程。封装是实现抽象的机制。

  2. Abstraction focuses on the observable behavior of an object. Encapsulation focuses upon the implementation that give rise to this behavior.

    抽象侧重于对象的可观察行为。封装侧重于导致此行为的实现。

Information Hiding - It is the process of hiding the implementation details of an object. It is a result of Encapsulation.

信息隐藏 - 隐藏对象的实现细节的过程。这是Encapsulation的结果。

#10


2  

Abstraction : Abstraction is the concept/technique used to identify what should be the external view of an object. Making only the required interface available.

抽象:抽象是用于识别对象的外部视图的概念/技术。仅提供所需的界面。

Information Hiding : It is complementary to Abstraction, as through information hiding Abstraction is achieved. Hiding everything else but the external view.

信息隐藏:它是对抽象的补充,因为通过信息隐藏抽象实现。隐藏除了外部视图之外的所有其他内容。

Encapsulation : Is binding of data and related functions into a unit. It facilitates Abstraction and information hiding. Allowing features like member access to be applied on the unit to achieve Abstraction and Information hiding

封装:将数据和相关功能绑定到一个单元中。它有助于抽象和信息隐藏。允许在单元上应用成员访问等功能以实现抽象和信息隐藏

#11


2  

See Joel's post on the Law of Leaky Abstractions

请参阅Joel关于漏洞抽象法的文章

JoelOnsoftware

Basically, abstracting gives you the freedom of thinking of higher level concepts. A non-programming analogy is that most of us do not know where our food comes from, or how it is produced, but the fact that we (usually) don't have to worry about it frees us up to do other things, like programming.

基本上,抽象可以让您*地思考更高层次的概念。一个非编程的类比是,我们大多数人都不知道我们的食物来自何处,或者它是如何产生的,但我们(通常)不必担心它会使我们*地做其他事情,比如节目。

As for information hiding, I agree with jamting.

至于信息隐藏,我同意干扰。

#12


1  

Abstraction allows you to treat a complex process as a simple process. For example, the standard "file" abstraction treats files as a contiguous array of bytes. The user/developer does not even have to think about issues of clusters and fragmentation. (Abstraction normally appears as classes or subroutines.)

抽象允许您将复杂过程视为一个简单过程。例如,标准“文件”抽象将文件视为连续的字节数组。用户/开发人员甚至不必考虑集群和碎片问题。 (抽象通常表现为类或子例程。)

Information hiding is about protecting your abstractions from malicious/incompetent users. By restricting control of some state (hard drive allocations, for example) to the original developer, huge amounts of error handling becomes redundant. If nobody else besides the file system driver can write to the hard drive, then the file system driver knows exactly what has been written to the hard drive and where. (The usual manifestation of this concept is private and protected keywords in OO languages.)

信息隐藏是为了保护您的抽象免受恶意/无能用户的侵害。通过将某些状态(例如硬盘驱动器分配)的控制限制为原始开发人员,大量的错误处理变得多余。如果除了文件系统驱动程序之外没有其他人可以写入硬盘驱动器,则文件系统驱动程序确切地知道已写入硬盘驱动器的位置以及位置。 (这个概念的通常表现形式是OO语言中的私有和受保护的关键字。)

#13


1  

To abstract something we need to hide the detail or to hide the detail of something we need to abstract it. But, both of them can be achieved by encapsulation.

要抽象一些东西,我们需要隐藏细节或隐藏我们需要抽象它的细节。但是,它们都可以通过封装来实现。

So, information hiding is a goal, abstraction is a process, and encapsulation is a technique.

因此,信息隐藏是一个目标,抽象是一个过程,封装是一种技术。

#14


1  

Abstraction simply means the technique in which only essential details of software is made visible to the user to help the user to use or operate with software, thus implementation details of that software are not shown(are made invisible). Encapsulation is the technique that have package that hold one or more items and hence some of information (particularly program details) became visible and some not visible to the user, so encapsulation is achieved through information hiding. In summary. Abstraction is for observable behavior (externally) and encapsulation is for invisibility (internally) but these two are really complementary.

抽象仅仅意味着这样一种技术,其中只有软件的基本细节对用户可见,以帮助用户使用或操作软件,因此不显示该软件的实现细节(使其不可见)。封装是具有包含一个或多个项目的包的技术,因此一些信息(特别是程序细节)变得可见并且一些对用户不可见,因此封装是通过信息隐藏来实现的。综上所述。抽象是为了可观察行为(外部),封装是为了隐形(内部),但这两者是真正互补的。

#15


1  

Just adding on more details around InformationHiding, found This link is really good source with examples

只是添加有关InformationHiding的更多详细信息,发现这个链接非常好,带有示例

InformationHiding is the idea that a design decision should be hidden from the rest of the system to prevent unintended coupling. InformationHiding is a design principle. InformationHiding should inform the way you encapsulate things, but of course it doesn't have to.

信息隐藏的想法是,应该从系统的其余部分隐藏设计决策,以防止意外耦合。信息隐藏是一种设计原则。 InformationHiding应该告知你封装事物的方式,当然它不需要。

Encapsulation is a programming language feature.

封装是一种编程语言功能。

#16


1  

I too was very confused about the two concepts of Abstraction and Encapsulation. But when I saw the abstraction article on myjavatrainer.com, It became clear to me that Abstraction and Encapsulation are Apples and Oranges, you can't really compare them because both are required.

我也对抽象和封装这两个概念感到非常困惑。但是当我在myjavatrainer.com上看到抽象文章时,我清楚地知道抽象和封装是苹果和橘子,你无法真正比​​较它们,因为两者都是必需的。

Encapsulation is how the object is created, and abstraction is how the object is viewed in the outside world.

封装是对象的创建方式,抽象是对象在外部世界中的查看方式。

#17


0  

After reading all the above answers one by one I cant stop myself from posting that

在逐一阅读上述所有答案后,我无法阻止自己发布

abstraction involves the facility to define objects that represent abstract "actors" that can perform work, report on and change their state, and "communicate" with other objects in the system.

抽象涉及定义表示抽象“actor”的对象的工具,这些对象可以执行工作,报告和更改其状态,并与系统中的其他对象“通信”。

Encapsulation is quite clear from above however ->

然而,封装从上面可以清楚地看出 - >

The term encapsulation refers to the hiding of state details, but extending the concept of data type from earlier programming languages to associate behavior most strongly with the data, and standardizing the way that different data types interact, is the beginning of abstraction.

术语封装是指隐藏状态细节,但是从早期编程语言扩展数据类型的概念,以最强烈地将行为与数据相关联,并标准化不同数据类型交互的方式,是抽象的开始。

reference wiki

#18


0  

Encapsulation: binding data and the methods that act on it. this allows the hiding of data from all other methods in other classes. example: MyList class that can add an item, remove an item, and remove all items the methods add, remove, and removeAll act on the list(a private array) that can not be accessed directly from the outside.

封装:绑定数据和作用于它的方法。这允许隐藏其他类中的所有其他方法的数据。示例:MyList类可以添加项目,删除项目,并删除方法添加,删除和删除所有项目列表(私有阵列)上无法直接从外部访问的所有项目。

Abstraction: is hiding the non relevant behavior and data. How the items are actually stored, added, or deleted is hidden (abstracted). My data may be held in simple array, ArrayList, LinkedList, and so on. Also, how the methods are implemented is hidden from the outside.

抽象:隐藏不相关的行为和数据。如何实际存储,添加或删除项目是隐藏的(抽象的)。我的数据可以保存在简单数组,ArrayList,LinkedList等中。此外,如何实现这些方法是从外部隐藏的。

#19


0  

Encapsulation- enforcing access to the internal data in a controlled manner or preventing members from being accessed directly.

封装 - 以受控方式强制访问内部数据或阻止成员直接访问。

Abstraction- Hiding the implementation details of certain methods is known as abstraction

抽象 - 隐藏某些方法的实现细节称为抽象

Let's understand with the help of an example:-

让我们借助一个例子来理解: -

class Rectangle
{
private int length;
private int breadth;// see the word private that means they cant be accesed from 
outside world.
 //now to make them accessed indirectly define getters and setters methods
void setLength(int length)
{  
// we are adding this condition to prevent users to make any irrelevent changes 
  that is why we have made length private so that they should be set according to 
   certain restrictions
if(length!=0)
{
 this.length=length
 }
void getLength()
{
 return length;
 }
 // same do for breadth
}

now for abstraction define a method that can only be accessed and user doesnt know what is the body of the method and how it is working Let's consider the above example, we can define a method area which calculates the area of the rectangle.

现在用于抽象定义一个只能访问的方法,用户不知道方法的主体是什么以及它是如何工作的让我们考虑上面的例子,我们可以定义一个计算矩形区域的方法区域。

 public int area()
 {
  return length*breadth;
 }

Now, whenever a user uses the above method he will just get the area not the way how it is calculated. We can consider an example of println() method we just know that it is used for printing and we don't know how it prints the data. I have written a blog in detail you can see the below link for more info abstraction vs encapsulation

现在,每当用户使用上述方法时,他将获得的区域不是计算方式。我们可以考虑println()方法的一个例子,我们只知道它用于打印,我们不知道它是如何打印数据的。我已经写了一篇详细的博客,你可以看到下面的链接,了解更多信息抽象与封装

#20


0  

It's worth noting these terms have standardized, IEEE definitions, which can be searched at https://pascal.computer.org/.

值得注意的是,这些术语具有标准化的IEEE定义,可以在https://pascal.computer.org/上进行搜索。

abstraction

  1. view of an object that focuses on the information relevant to a particular purpose and ignores the remainder of the information
  2. 一个对象的视图,该对象侧重于与特定目的相关的信息,并忽略其余信息

  3. process of formulating a view
  4. 制定观点的过程

  5. process of suppressing irrelevant detail to establish a simplified model, or the result of that process
  6. 抑制不相关细节以建立简化模型或该过程结果的过程

information hiding

  1. software development technique in which each module's interfaces reveal as little as possible about the module's inner workings and other modules are prevented from using information about the module that is not in the module's interface specification
  2. 软件开发技术,其中每个模块的接口尽可能少地揭示模块的内部工作和其他模块被阻止使用有关模块的信息不在模块的接口规范中

  3. containment of a design or implementation decision in a single module so that the decision is hidden from other modules
  4. 在单个模块中包含设计或实现决策,以便从其他模块中隐藏决策

encapsulation

  1. software development technique that consists of isolating a system function or a set of data and operations on those data within a module and providing precise specifications for the module
  2. 软件开发技术,包括在模块内隔离系统功能或一组数据和操作,并为模块提供精确的规范

  3. concept that access to the names, meanings, and values of the responsibilities of a class is entirely separated from access to their realization
  4. 这样一种概念,即对类的职责的名称,含义和价值的访问与对其实现的访问完全分开

  5. idea that a module has an outside that is distinct from its inside, that it has an external interface and an internal implementation
  6. 认为模块具有与其内部不同的外部,它具有外部接口和内部实现