Xceedas

Xceedas
xceedas

Wednesday 10 September 2014

Difference Between Encapsulation and Abstraction

Difference between Encapsulation and Abstraction
There is a very basic difference between encapsulation and abstraction for beginners of OOP. They might get
confused by it. But there is huge difference between them if you understand both the topics in detail.
Abstraction means to hide the unnecessary data from the user. The user only needs the required functionality or the
output according to his requirements. For example a digital camera.
Dear reader, whenever we use a digital camera, we just click on the Zoom In and Zoom Out buttons and the camera
zooms in and out but we can feel the lens moving. If we open the camera then we will see its complex mechanism that
we can't understand. So pressing the button and getting the results according to your demand is the abstraction.Encapsulation is simply combining the data members and functions into a single entity called an object.
If we consider the camera example again, when we press zoom In/Out buttons, inside the camera it uses mechanisms
that consists of gears and lenses to zoom in or zoom out. The combination of gears and lenses is called encapsulation
that will help the zooming functionality to work smoothly.
In simple words we can say that "Abstraction is achieved through encapsulation".
Or
Abstraction solves the problem in the design side while encapsulation is the implementation.

No comments :