Saturday, September 25, 2010

Abstraction in Java

Hiding unnecessary data from the user is called abstraction. Abstraction is the process of recognizing and focusing on important characteristics of an object and filtering out un-wanted characteristics of an object.
Real time example: A person can be abstracted differently in different situations.
A doctor sees a person as a patient. The doctor is interested in person’s name, height, weight, age, blood group and diseases. Where as an employer is interested in the person’s name, degree, percentage, work experience etc.
This is a beautiful example for abstraction.
In java Interface follows the concept of abstraction.


One of my friend Rajesh Hegde gives this concept about data abstraction.
Abstraction is a way to remove the association of the behavior of an object with the actual details behind the scenes which implement that object's behavior.This 'abstraction' is usually accomplished through the use of base classes with virtual functions; each derived function provides the details that implement the behavior behind that abstraction.A simple example is using a base class "Animal", with a virtual function "Walk". In the case two-legged versus four-legged animals, both of them walk, but the actual mechanics are different. The "Walk" method abstracts the actual mechanics behind the walking that each "Animal" does.

1 comment:

Bishal Kumar said...

nicely explained. Being very rusty and lazy to recall the codes behind the scene, Wished a java code as an example :-)