抽象VS信息隱藏VS封裝 (Abstraction VS Information Hiding VS Encapsulation)


問題描述

抽象 VS 信息隱藏 VS 封裝 (Abstraction VS Information Hiding VS Encapsulation)

你能告訴我軟件開發中抽象信息隱藏有什麼區別嗎?

我很困惑。抽象隱藏細節實現,而信息隱藏抽象某事物的全部細節。

更新:我為這三個概念找到了一個很好的答案。請參閱下面的單獨答案以獲取來自 那裡


參考解法

方法 1:

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,

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

方法 2:

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.

(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]

"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]

"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:

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 putting 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:

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 :

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

方法 5:

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

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.

(by popopomerp.stakx ‑ no longer contributingShashwatRashyjamting)

參考文件

  1. Abstraction VS Information Hiding VS Encapsulation (CC BY‑SA 2.5/3.0/4.0)

#ooad #abstraction #encapsulation #information-hiding #glossary






相關問題

接口實現是否應該獨立 (Should Interface implementations be independent)

當我們有不同的回報類型時實現策略模式 (Achieve strategy pattern when we have different return type)

抽象VS信息隱藏VS封裝 (Abstraction VS Information Hiding VS Encapsulation)

應用程序中jQuery表單綁定代碼的最佳實踐 (Best practices with jQuery form binding code in an application)

耦合與內聚 (Coupling and cohesion)

什麼時候應該在C ++中使用類與結構? (When should you use a class vs a struct in C++?)

What is an anti-pattern? (What is an anti-pattern?)

如何根據編程代碼顯示聚合? (How to Show Aggregation in terms of A Programming Code?)

協調 MVP 三元組 (Coordinating MVP triads)

裝飾器和虛擬方法 (Decorators and Virtual Methods)

設計和建築有什麼區別? (What is the difference between Design and Architecture?)

特定時間段有效的業務規則——如何有序管理 (Business rules that are valid for specific time span – how to manage in an orderly manner)







留言討論