I was in some interview and interviewer ask me the question to differentiate these terms of OOPs Abstraction, Encapsulation, and Information Hiding.
But at that time I'm not able to give the accurate information and differentiation with these terms.
Then, I was curious. I decided to gather a number of different definitions for abstraction, information hiding, and encapsulation, and to compare them. This article details what I found.
But at that time I'm not able to give the accurate information and differentiation with these terms.
Then, I was curious. I decided to gather a number of different definitions for abstraction, information hiding, and encapsulation, and to compare them. This article details what I found.
ABSTRACTION
"A view of a problem that extracts the essential information
relevant to a particular purpose and ignores the remainder of
the information." -- [IEEE, 1983]
"The essence of abstraction is to extract essential properties while omitting inessential details."
-- [Ross et al, 1975]
"An abstraction denotes the essential characteristics of an object that distinguish it from all other kinds of object and thus provide crisply defined conceptual boundaries, relative to the perspective of the viewer."
-- [Booch, 1991]
One point of confusion regarding abstraction is its use as both a 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. Abstraction is most often used as a complexity mastering technique. For example, we often hear people say such things as: "just give me the highlights" or "just the facts, please." What these people are asking for are abstractions.
We can have varying degrees of abstraction, although these "degrees" are more commonly referred to as "levels." As we move to higher levels of abstraction, we focus on the larger and more important pieces of information (using our chosen selection criteria). Another common observation is that as we move to higher levels of abstraction, we tend to concern ourselves with progressively smaller volumes of information, and fewer overall items. As we move to lower levels of abstraction, we reveal more detail, typically encounter more individual items, and increase the volume of information with which we must deal.
We also note that there are many different types of abstraction, e.g., functional abstraction, data abstraction, process abstraction, and even object abstraction.
"The essence of abstraction is to extract essential properties while omitting inessential details."
-- [Ross et al, 1975]
"An abstraction denotes the essential characteristics of an object that distinguish it from all other kinds of object and thus provide crisply defined conceptual boundaries, relative to the perspective of the viewer."
-- [Booch, 1991]
One point of confusion regarding abstraction is its use as both a 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. Abstraction is most often used as a complexity mastering technique. For example, we often hear people say such things as: "just give me the highlights" or "just the facts, please." What these people are asking for are abstractions.
We can have varying degrees of abstraction, although these "degrees" are more commonly referred to as "levels." As we move to higher levels of abstraction, we focus on the larger and more important pieces of information (using our chosen selection criteria). Another common observation is that as we move to higher levels of abstraction, we tend to concern ourselves with progressively smaller volumes of information, and fewer overall items. As we move to lower levels of abstraction, we reveal more detail, typically encounter more individual items, and increase the volume of information with which we must deal.
We also note that there are many different types of abstraction, e.g., functional abstraction, data abstraction, process abstraction, and even object abstraction.
INFORMATION HIDING
"The technique of encapsulating software design decisions in
modules in such a way that the module's interfaces reveal little
as possible about the module's inner workings; thus each module is
a 'black box' to the other modules in the system." -- [IEEE, 1983]
"... the purpose of hiding is to make inaccessible certain details that should not affect other parts of a system."
-- [Ross et al, 1975]
"... the purpose of hiding is to make inaccessible certain details that should not affect other parts of a system."
-- [Ross et al, 1975]
ENCAPSULATION
"It is a simple, yet reasonable effective, system-building
tool. It allows suppliers to present cleanly specified
interfaces around the services they provide. A consumer has full
visibility to the procedures offered by an object, and no visibility
to its data. From a consumer's point of view, and object is a
seamless capsule that offers a number of services, with no
visibility as to how these services are implemented ... The
technical term for this is encapsulation." -- [Cox, 1986]
"The concept of encapsulation as used in an object-oriented context is not essentially different from its dictionary definition. It still refers to building a capsule, in the case a conceptual barrier, around some collection of things." -- [Wirfs-Brock et al, 1990]
Like abstraction, the word "encapsulation" can be used to describe either a process or an entity. As a process, encapsulation means the act of enclosing one or more items within a (physical or logical) container.
Programming languages have long supported encapsulation. For example, subprograms (e.g., procedures, functions, and subroutines), arrays, and record structures are common examples of encapsulation mechanisms supported by most programming languages.
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. For example, even though information may be encapsulated within record structures and arrays, this information is usually not hidden (unless hidden via some other mechanism).
- Brad Cox's definition ([Cox, 1986]) allows for encapsulation to hide some information ("full visibility to the procedures offered by an object"), while hiding other information ("no visibility to its data").
At the end we can say that encapsulation is the process to wrap-up the related data. It also provide security over this wrap-up by applying access modifiers like public, protected, private etc.
"The concept of encapsulation as used in an object-oriented context is not essentially different from its dictionary definition. It still refers to building a capsule, in the case a conceptual barrier, around some collection of things." -- [Wirfs-Brock et al, 1990]
Like abstraction, the word "encapsulation" can be used to describe either a process or an entity. As a process, encapsulation means the act of enclosing one or more items within a (physical or logical) container.
Programming languages have long supported encapsulation. For example, subprograms (e.g., procedures, functions, and subroutines), arrays, and record structures are common examples of encapsulation mechanisms supported by most programming languages.
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. For example, even though information may be encapsulated within record structures and arrays, this information is usually not hidden (unless hidden via some other mechanism).
- Brad Cox's definition ([Cox, 1986]) allows for encapsulation to hide some information ("full visibility to the procedures offered by an object"), while hiding other information ("no visibility to its data").
At the end we can say that encapsulation is the process to wrap-up the related data. It also provide security over this wrap-up by applying access modifiers like public, protected, private etc.
CONCLUSIONS
Abstraction, information hiding, and encapsulation are very different,
but highly-related, concepts. One could argue that abstraction is a
technique that helps 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.
No comments:
Post a Comment