Wiki puts it very accurately
Data abstraction
Data abstraction provides a clear separation between the abstract properties of a data type and the specific details of its implementation. Abstract properties are those that are visible to client code that uses a data type β an interface to a data type, and the particular implementation is completely closed and can really change, for example, in order to increase efficiency over time. The idea is that such changes should not have any effect on the client code, since they do not have a difference in abstract behavior. For example, you can define an abstract data type called a lookup table that uniquely associates keys with values ββand in which values ββcan be obtained by specifying their corresponding keys. Such a lookup table can be implemented in various ways: both a hash table, a binary search tree, and a simple linear list of pairs (key: value). As for the client code, the abstract properties of this type are the same in each case.
Consider, for example, a sample Java fragment to present some common βanimalβ farms to an abstraction level suitable for modeling simple aspects of their hunger and nutrition. It defines a class of animals to represent the state of the animal and its functions:
public class Animal extends LivingThing { private Location loc; private double energyReserves; public boolean isHungry() { return energyReserves < 2.5; } public void eat(Food f) {
Using the above definition, you can create objects of type Animal and call their methods as follows:
thePig = new Animal(); theCow = new Animal(); if (thePig.isHungry()) { thePig.eat(tableScraps); } if (theCow.isHungry()) { theCow.eat(grass); } theCow.moveTo(theBarn);
source share