pankaj vijay wrote:
i am very confused between Encapsulation & Abstraction & Data Hiding.... they all seems like same...
as per my knowledge encapsulation means containing many thing like fields members in an object is encapsulation
Hiding inner working form user is abstraction. while not showing field to the user is Data Hiding...
but am i right???
When you encapsulate something you get an inside and an outside. The outside is data abstraction and the inside is information hiding. Encapsulation concerns how strong this division is, that is to what extent you can poke inside from the outside.
The main encapsulation
unit in
Java is the class. In principle everything that's exposed to the outside, namely all non-private members, constitute the data abstraction. Hidden inside is the implementation.
An interface is a pure data abstraction.
In object orientation data abstraction manifests itself as user defined types (a type is what you declare variables to be of). Information hiding is the ability to hide information as private members of a class (an enum in Java is a specialized class). So data abstraction is when you define types using the class, interface and enum facilities of Java.
Encapsulation is the ability to separate the what from the how. That is the type (the abstract outside) from how it works inside (a concrete hidden implementation). Encapsulation also is related to questions of mutability/immutability, that is to what extent and how well the inside is isolated from the outside.