Академический Документы
Профессиональный Документы
Культура Документы
ADT Definition
ADT is a mathematical model of a set of data items and operations on the data items. Implementation consists of
Storage (data) structures Algorithms for basic operations
ADT does not imply how these operations are implemented Typical ADTs are Lists, Stacks, Queues, Sets, Maps, Graphs and Priority Queues
Operations:
Binary arithmetic operations: +, -, *, /, % Unary arithmetic operations: +, Relational operations: ==, !=, <, <=, >, >=
ADTs in C
C is not object-oriented, but we can still manage to inject some object-oriented principles into the design of C code. For example, a data structure and its operations can be packaged together into an entity called an ADT. Theres a clean, simple interface between the ADT and the program(s) that use it. The lower-level implementation details of the data structure are hidden from view of the rest of the program. The implementation details can be changed without altering the ADT interface. This can be accomplished by creating the ADT in three different files:
One to hold the type and constant definitions. One to hold the prototypes of the functions in the ADTs (public) interface. One to hold the implementations of the public and private functions.
ADT Contd.
Data abstraction, or abstract data types, is a programming methodology where one defines not only the data structure to be used, but the processes to manipulate the structure
like process abstraction, ADTs can be supported directly by programming languages
information hiding to protect the data structure from outside interference or manipulation
the data structure should only be accessible from code encapsulated with it so that the structure is hidden and protected from the outside objects are one way to implement ADTs, but because objects have additional properties, we defer discussion of them until the next chapter
Information hiding: controlling access to the data structure through some form of interface so that it cannot be directly manipulated by external code
this is often done by using two sections of an ADT definition
public part (interface) constitutes those elements that can be accessed externally (often the interface permits only access to subprograms and constants) the private part, which remains secure because it is only accessible by subprograms of the ADT itself
ADT module
Unit for encapsulation called a module
modules can be combined to form libraries of ADTs
To define a module:
definition module: the interface containing a partial or complete type definition (data structure) and the subprogram headers and parameters implementation module: the portion of the data structure that is to be hidden, along with all operation subprograms
If the complete type declaration is given in the definition module, the type is transparent otherwise it is opaque
opaque types represent true ADTs and must be accessed through pointers
this restriction allows the ADT to be entirely hidden from user programs since the user program need only define a pointer