You get a bonus - 1 coin for daily activity. Now you have 1 coin

Opaque Data Type

Lecture



In computer science , an opaque data type is a data type whose concrete data structure is not defined in the interface . This provides information hiding , since its values can only be manipulated by calling subroutines that have access to the missing information. The concrete representation of the type is hidden from its users, and the visible implementation is incomplete. A data type whose representation is visible is called transparent . Opaque data types are often used to implement abstract data types .

An opaque data type is a data type in computer science whose data structure is not specified in its interface . Such a type strengthens information hiding , since its value can only be used by subroutines that have access to the missing information.

Opaque data types are often used to implement abstract data types .

Data types whose data structure is visible are called transparent data types .

Well-known examples of opaque data types are the handles and resources of an operating system , provided to an application program . For example, POSIX Threads defines an application programming interface that uses opaque data types to represent threads of execution and synchronization primitives such as mutexes and condition variables .

An opaque pointer is a special case of an opaque data type. It is a pointer to a record or data structure of the given type. For example, the standard library, which is part of the C programming language specification , uses a pointer to FILE for file input/output, whose concrete implementation is defined.

In various programming languages

Some programming languages, such as C, can describe opaque data types whose fields and size are hidden from clients. A client can only obtain the address of an object of that type and create an opaque pointer.Some languages, such as C , allow the declaration of opaque records (structures) whose size and fields are hidden from the client. The only thing a client can do with an object of such a type is take its memory address , in order to create an opaque pointer .

If the interface allows the size of the type to be determined, then clients can allocate memory and copy such objects.

In some languages, such as Java , the only kind of opaque type is the opaque pointer. Indeed, in Java (and some other languages) records are always handled via pointers. In the Java language, opaque types can only be opaque pointers.

Some programming languages allow the definition of partially opaque types. Some fields may be open, while all others are hidden. This is one of the foundations of object-oriented programming .

Typical examples of opaque data types include the handle for resources provided by an operating system to application software . For example, the POSIX standard for threads defines an application programming interface based on a set of opaque types that represent threads or synchronization primitives, such as mutexes or condition variables .

An opaque pointer is a special case of an opaque data type, a data type that is declared to be a pointer to a record or data structure of some unspecified data type. For example, the standard library, which is part of the C programming language specification, provides functions for file input and output that return or accept values of type «pointer to », which represent file streams (see C file input/output ), but the concrete implementation of the type FILEFILE type is not specified.

If the information provided by the interface is sufficient to determine the size of the type, then clients can declare variables , fields and arrays of that type, assign their values, and possibly compare them for equality. This is usually the case for opaque pointers.

Some languages allow partially opaque types, for example a record that has some open fields, known and accessible to all clients, and some hidden fields, which are not shown in the interface. Such types play a fundamental role in object-oriented programming .

Information that is missing from the interface may be declared in its implementation or in another «friends-only» interface. This second parameter allows the hidden information to be shared by two or more modules.

Application

Typical examples of these opaque data types are the extensive operating system resources , which are accessible to the user through software applications. The data type is hidden from the user because it is only significant to the operating system. It is also possible to change this data type on the operating system side without needing to adapt the source code of application programs.

This refers to the Portable Operating System Interface (POSIX) , an application program interface that represents the interface between application software and the operating system.

Definition in modular programming

Opaque data types are also used in modular programming languages, such as Modula-2 , a further development of Pascal . Implementation occurs by means of so-called modules . All parts, compiled separately from the main program, are split into two files: the definition module and the 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. Therefore this must be described in the implementation module. Consequently, this is an opaque (non-transparent) data type.

By contrast, there is a data type whose representation is visible. This data type is again called «transparent».

Using opaque data types (example)

Opaque Data Type

Description

In the case of an opaque data type, the description of the structure of the associated opaque data objects is defined elsewhere and is not accessible to the user of the data type. It uses only the name of the opaque data type TStack to declare opaque data objects (1). Access is no longer achieved by directly modifying or reading objects using knowledge of their detailed structure, but only by means of access operations (2).

Using transparent data types (example)

Opaque Data Type

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 defines its structure in the subsequent type definition, here a field of n elements of any data type. This structure is considered disclosed, so a normal data type is also called a transparent data type. Using the type identifier, which represents the description of the structure, a data object of this type can now be declared in a data object declaration (4). Since its detailed structure is known, it is possible to make a reference for manipulating this data object (5).

See also

  • Abstract data type
  • Black box
  • Transparent identifiers
  • Forward declaration
  • Information hiding
  • Type system
  • Type safety
  • Logicism
  • Many-sorted logic
  • Data type for concrete data types in programming
  • Domain theory
  • Type (model theory)
  • Type system for a more practical discussion of type systems for programming languages
  • Universal foundations
  • Applicative computing systems
  • Typed λ-calculus
  • Combinatory logic
  • Functional programming
  • Anonymous function
  • Algebraic data type, data constructor, type constructor
  • Recursive data type
  • Subtype
  • Function type
  • Type polymorphism and type variable
  • Type class
  • Type theory
  • Kind (type theory)
  • Abstract data type
  • data structures [[b4380]]
  • [[b4403]]
  • [[b9803]]
  • [[b3764]]
  • [[b9144]]
  • [[b5775]]
  • [[b5301]]
  • variable

See also

created: 2020-05-17
updated: 2026-03-09
186



Was this answer useful?
Choose a quick rating so we can improve the next answer for you.
How satisfied are you?


Comments

To leave a comment

If you have any suggestion, idea, thanks or comment, feel free to write. We really value feedback and are glad to hear your opinion.
To reply

Lectures and tutorial on "Structures and data processing algorithms."

Terms: Structures and data processing algorithms.