Originally posted by Margaret Tan:
How is abtraction different from polymorphism?
As Mike said, they are different but often go hand-in-hand.
The purpose of Abstraction is to extract the "essence" of something and hide the details. For example, the icons on your desktop (assuming you're using some GUI OS like Windows). The icons are abstractions of the actual entities that exist on your system, usually an executable program. The act of clicking on the icon is an abstraction for certain OS commands required to perform a certain task. That is, when you click (or double click, as the case may be) on the icon, something will happen. You don't really care what the details of making something happen are just as long as it happens. The OS takes care of the actual details.
By the same token, an abstract Java class defines an interface that guarantees certain services to be available to users of that class. Users don't care about the details, they just need to know that the capability is there.
Polymorphism, which means "many forms", usually refers to the ability to treat different objects the same way. Going back to the desktop icon example, some icons may not represent executable programs: they may represent documents instead. However, the interface is still pretty much the same in that you can click/double-click on the icon and the program that is used to manipulate the document will be started with the document loaded. The essential thing is that something happens when you click on the icon.
By using an abstraction (click on the icon, do something), you can use different objects (program or document) polymorphically and invoke capabilities or behavior (run program or edit document).
------------------
Junilu Lacar
Sun Certified Programmer for the Java� 2 Platform
[This message has been edited by JUNILU LACAR (edited October 26, 2001).]
[This message has been edited by JUNILU LACAR (edited October 26, 2001).]