Opaque data type

from Wikipedia, the free encyclopedia

As opaque (engl. F. Opaque) data type is referred to in the field of computer science a data type , the physical representation (representation) or irrelevant either unknown. The data structure of an opaque data type is not defined solely on a limit area. The specific type of representation remains opaque (hidden) for the user and the visible implementation is incomplete.

Opaque data types, that is, opaque data types, are often used to implement abstract data types.

Applications

Typical examples of these opaque data types are the extensive resources of an operating system , which are made available to the user with the help of software applications. The data type is hidden from the user because it is only important for the operating system. It is also possible to change this data type in the operating system without having to adapt the source code of the application programs.

It is about the Portable Operating System Interface (POSIX) , an application program interface that represents an interface between application software and the operating system.

Definition in modular programming languages

Opaque data types are also used in modular programming languages such as Modula-2 , a further development of Pascal . A realization or implementation takes place with the help of so-called modules . All parts translated separately from the main program are split into two files, a definition module and an implementation module.

Only the type name and the interface are specified in the definition module. The type specification itself is not given, so the structure of the data type remains hidden. This must therefore be described in the implementation module. It is therefore an opaque (non-transparent) data type.

In contrast to this, there is a data type whose representation becomes visible. This data type is again referred to as "transparent".

Use of opaque data types (example)

var stack: TStack; // (1)
if stack.Count() > 0 then // (2)
    stack.Pop();
else
    ...
end;

description

With an opaque data type, the structure description of the associated opaque data objects is defined elsewhere and is not accessible to the user of the data type. It only uses the name of the opaque data type TStackto declare opaque data objects (1). Access does not take place by changing or reading objects directly, using knowledge of their detailed structure, but exclusively using access operations (2).

Use of transparent data types (example)

type TSpace = array[1..n] of TItem; // (3)
var space: TSpace; // (4)
if ... then
    space[index] := x;
else
    ...
end; // (5)

description

A normal data type is introduced by a type declaration (3), which defines the name of the type, in this example TSpace, and which specifies its structure in the subsequent type definition, here an n-element field of any data type. This structure is considered to be open, which is why a normal data type is also called a transparent data type. With the help of the type identifier that represents the structure description, a data object of this type can now be declared in a data object declaration (4). Since its detailed structure is known, it can be referred to when manipulating this data object (5).

See also

Individual evidence

  1. ^ Daniel P. Friedman and Mitchell Wand: Essentials of Programming Languages. Third edition. (PDF; 3.41 MB), October 30, 2015.
  2. Jörg Puchan, Wolffried Stucky, Jürgen Frhr. Wolff von Gudenberg: Programming with Modula-2. Teubner, 1994, ISBN 3-519-12934-5 .