ABSTRACT DATA TYPE
In computing, an abstract data
type or abstract data structure is a mathematical model for a certain class of
data structures that have similar behavior; or for certain data types of one or
more programming languages that have similar semantics. An abstract data type
is defined indirectly, only by the operations that may be performed on it and
by mathematical constraints on the effects (and possibly cost) of those
operations.For example, an abstract stack data structure could be defined by
two operations: push, that inserts some data item into the structure, and pop,
that extracts an item from it; with the constraint that each pop always returns
the most recently pushed item that has not been popped yet. When analyzing the
efficiency of algorithms that use stacks, one may also specify that both
operations take the same time no matter how many items have been pushed into
the stack, and that the stack uses a constant amount of storage for each
element.
Abstract data types are purely
theoretical entities, used (among other things) to simplify the description of
abstract algorithms, to classify and evaluate data structures, and to formally
describe the type systems of programming languages. However, an ADT may be
implemented by specific data types or data structures, in many ways and in many
programming languages; or described in a formal specification language. ADTs
are often implemented as modules: the module's interface declares procedures
that correspond to the ADT operations, sometimes with comments that describe
the constraints. This information hiding strategy allows the implementation of
the module to be changed without disturbing the client programs.The notion of
abstract data types is related to the concept of data abstraction, important in
object-oriented programming and design by contract methodologies for software
development.
Example and Real life
application:The first thing with which one is confronted when writing programs
is the problem. Typically you are confronted with ``real-life'' problems and you
want to make life easier by providing a program for the problem. However,
real-life problems are nebulous and the first thing you have to do is to try to
understand the problem to separate necessary from unnecessary details: You try
to obtain your own abstract view, or model, of the problem. This process of
modeling is called abstraction and is illustrated in Figure .
The model defines an abstract view
to the problem. This implies that the model focusses only on problem related
stuff and that you try to define properties of the problem. These properties
include
• the
data which are affected and
• the
operations which are identified
by the problem. As an example consider the administration of
employees in an institution. The head of the administration comes to you and
ask you to create a program which allows to administer the employees. Well,
this is not very specific. For example, what employee information is needed by
the administration? What tasks should be allowed? Employees are real persons
who can be characterized with many properties; very few are:
• name,
• size,
• date
of birth,
• shape,
• social
number,
• room
number,
• hair
colour,
• hobbies.
Certainly not all of these properties
are necessary to solve the administration problem. Only some of them are
problem specific. Consequently you create a model of an employee for the
problem. This model only implies properties which are needed to fulfill the
requirements of the administration, for instance name, date of birth and social
number. These properties are called the data of the (employee) model. Now you
have described real persons with help of an abstract employee.
Of course, the pure description is
not enough. There must be some operations defined with which the administration
is able to handle the abstract employees. For example, there must be an
operation which allows you to create a new employee once a new person enters
the institution. Consequently, you have to identify the operations which should
be able to be performed on an abstract employee. You also decide to allow
access to the employees' data only with associated operations. This allows you
to ensure that data elements are always in a proper state. For example you are able
to check if a provided date is valid.
To sum up, abstraction is the
structuring of a nebulous problem into well-defined entities by defining their
data and operations. Consequently, these entities combine data and operations.
They are not decoupled from each other.
An abstract data type (ADT) is
characterized by the following properties:
1. It exports a type.
2. It exports a set of operations.
This set is called interface.
3. Operations of the interface are
the one and only access mechanism to the type's data structure.
4. Axioms and preconditions define
the application domain of the type.
With the first property it is
possible to create more than one instance of an ADT as exemplified with the
employee example. However, all of these properties are only valid due to our
understanding of and our discipline in using the list module. It is in our
responsibility to use instances of List according to these rules.
No comments:
Post a Comment