ADT

From APIDesign

(Redirected from Abstract Data Type)
Jump to: navigation, search

ADT stands for Abstract Data Type - an API design style where one knows operations for a type, but not their actual implementation. In contrary to OOP, the right operation isn't derived from the actual object - rather it is associated with the whole algorithm that operates on provided data.

In classical OOP each object comes with a virtual message table - a table of actual implementations of functions (e.g. messages) the object understands to and can react to. In a typed language like Java each non-final, non-static method of a class has an entry in the virtual method table. E.g. Object shall have a table with following methods:

  • toString
  • hashCode
  • equals
  • clone
  • finalize

The table is different for each class. It can point to the same or different implementation of the methods or even add additional entries into the table. When one calls such method, like toString:

static String message(Object who) {
  return "Hello " + who.toString();
}

the compiled code finds the virtual method table for object who, locates the proper implementation of toString at the right index of the toString methods and only then invokes the implementation. In OOP operations are inherently associated with data - e.g. object.

Abstract Data Types

Some functional language (like Haskell also provide classes), but they do it differently. For example there may be a class Arithmetic:

class Arithmetic {
  Aritmetic plus(Arithmetic, Arithmetic);
}

TBD

Personal tools
buy