Abstraction in object-oriented programming
In object-oriented programming theory, abstraction is the facility to define objects that represent abstract "actors" that can perform work, report on and change their state, and "communicate" with other objects in the system.
The simplest form of it extends the concept of data type from earlier programming languages to associate behavior more strongly with the data. This is done to achieve encapsulation and a limited degree of polymorphism. These terms are very often used in contradicatory ways by users of various object-oriented progamming languages, which offer similar facilities for abstraction.
For example, Linda abstracts the concepts of server and shared data-space to facilitate distributed programming. In CLOS or self, for example, there is less of a class-instance distinction, more use of delegation for polymorphism, and individual objects and functions are abstracted more flexibly to better fit with a shared functional heritage from LISP.
In the Java, a simple and widely used language, the term abstraction refers most commonly to an extended data type called a class - while objects of that type are called instances of that class. Relying overmuch on Java terminology is quite misleading, but Java examples proliferate on the Internet and it is relatively easy to find good examples from many problem domains.
For example, here is a sample Java fragment to represent some common farm "animals" to a level of abstraction suitable to model simple aspects of their hunger and feeding. It defines an Animal class to represent both the state of the animal and its functions:
class Animal extends LivingThing { Location m_loc; double m_energy_reserves; boolean is_hungry() { if (m_energy_reserves < 2.5) { return true; } else { return false; } } void eat(Food f) { // Consume food m_energy_reserves += f.getCalories(); } void moveto(Location l) { // Move to new location m_loc = l; } }
With the above definition, one could create objects of type Animal and call their methods like this:
thePig = new Animal(); theCow = new Animal(); if (thePig.is_hungry()) { thePig.eat(table_scraps); } if (theCow.is_hungry()) { theCow.eat(grass); } theCow.move(theBarn);
Lots more to say here about how different languages deal with abstraction, etc...