~ Office Supplies ~~ Buy Posters ~~ A-Z Products ~~ Website Advertising


Abstraction (computer science) - Wikipedia

<<Up     Contents

Abstraction (computer science)

Redirected from Abstraction (programming)

In computer science, abstraction is a technique to factor out details and ease use of code and data. It is by analogy with abstraction[?] in mathematics[?].

Control abstraction, seen in structured programming, is use of subprograms and control flows[?]. Data abstraction is primary motivation of introducing datatype and subsequently abstract data types.

Object-oriented programming can be seen as an attemp to abstract both data and code.

Examples are lambda abstractions (making a term into a function of some variable), higher-order functions (parameters are functions), bracket abstraction[?] (making a term into a function of a variable).

The opposite abstraction is concretisation[?].

This article (or an earlier version of it) contains material from FOLDOC, used with permission. Modify if needed.

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 Java, abstraction takes place at the level of extended data types. Such types are called a classes, and objects are instances of some class.

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);

In the above example, the class animal is an abstraction used in place of an actual animal, LivingThing is a further abstraction (in this case a generalisation) of animal.

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 Java, abstraction takes place at the level of extended data types. Such types are called a classes, and objects are instances of some class.

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);

In the above example, the class animal is an abstraction used in place of an actual animal, LivingThing is a further abstraction (in this case a generalisation) of animal.

Lots more to say here about how different languages deal with abstraction, etc...

wikipedia.org dumped 2003-03-17 with terodump




 
 
11 grams orange pink BOTSWANA AGATE gem stone tumble polished cab lapidary rough jewelry gemstone
 11 grams orange pink BOTSWANA AGATE tumble polished cab lapidary jewelry  
 
25 carats CHRYSOBERYL gems stones Facet uncut raw rough gemstones crystals lot 2 to 3 ct jewels Nice
 25 carats CHRYSOBERYL uncut raw crystals lot 2 to 3 ct jewels Nice 
 
14 gram red blue gold PIETERSITE gem stone Tumbled cab cabbing rough raw gemstone 73 carat PRETTY
 14 gram red blue gold PIETERSITE Tumbled cab cabbing raw 73 carat PRETTY 
 
137 carats gray AGATE gem Polished slab rectangle block Cabbing cab cabochon rough gemstone 27 grams
 137 carats gray AGATE Polished slab rectangle block Cabbing cab cabochon 27 grams 
 
245 carats gray AGATE gem Polished cut slab square block Cabbing cab cabochon rough gemstone 49 gram
 245 carats gray AGATE Polished cut slab square block Cabbing cab cabochon 49 gram