This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Just imagine interface as something you can see and Implementation as something you cannot see. So when you press accelerator of your car, you would never know how speed of car increases but it does. If you create a Accelerator interface, it can define you the template. Something like, to be an accelerator, you need to implement these set of methods. Now the implementation depends on which car manufacturer designs it. May be slight different way of doing for different car manufacturers.
To elaborate on davids example, List defines a template(sets up the essentials) to be able to hold objects as a list. ArrayList implements List to announce that it follows the template to be a list and it has its own way of doing it that you dont need to worry about. So List is an abstraction to Arraylist implementation.
In terms of Java code, even data hiding is abstraction. Like you make you instance variables as private so that only methods inside that class can change it and you provide to the world, a setter and getter method to change instance variable values. You can write your own rules inside these methods and the world has to follow it.
There are many places in Java where you would use abstraction.
Biggest advantage: I dont change my accelerator interface, but impliment new way of accelerating. Still the world see it as a peddle that can be pressed and speed increases.
This is my understanding. Please correct me if you think different.
as i am a new user to the forum, so i didn't knew the rules of the forum.Now i will keep this in mind.
thanks for all the users for their informative answers..
Joined: May 14, 2010
after searching more about this topic in this forum and other websites..i am writing my mind about abstraction here..
Definition: Abstraction simply means hiding non-essentianl details.
Implementation: The most simple example of Abstraction is .equals(object o). this function is provided to match two objects in java. we don't know or needn't know how the method is coded by the java team, but it provided us that function and we have to simply use it.
Am i right, if wrong, please correct me..
Joined: Oct 13, 2005
I would say that abstraction means hiding as many details as possible. Expose only what you really have to. Also it means reducing something to its bare essentials. Like a car. You have a wheel; turn it right and the car goes right. All cars have a similar steering wheel and it does the same thing. But we don't necessarily know how it works.