Abstraction VS Information Hiding VS Encapsulation

2019-01-01 01:26发布

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条回答
怪性笑人.
2楼-- · 2019-01-01 01:43

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

查看更多
君临天下
3楼-- · 2019-01-01 01:45

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.

查看更多
情到深处是孤独
4楼-- · 2019-01-01 01:47

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

查看更多
看风景的人
5楼-- · 2019-01-01 01:49

It's worth noting these terms have standardized, IEEE definitions, which can be searched at 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. process of formulating a view
  3. process of suppressing irrelevant detail to establish a simplified model, or the result of that process

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. containment of a design or implementation decision in a single module so that the decision is hidden from other modules

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. concept that access to the names, meanings, and values of the responsibilities of a class is entirely separated from access to their realization
  3. idea that a module has an outside that is distinct from its inside, that it has an external interface and an internal implementation
查看更多
无与为乐者.
6楼-- · 2019-01-01 01:53

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.

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

查看更多
妖精总统
7楼-- · 2019-01-01 01:55

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

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.

Encapsulation is a programming language feature.

查看更多
登录 后发表回答