Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

Opaque data type

From Wikipedia, the free encyclopedia
In computing, a data type whose structure is not defined in an interface
icon
This articleneeds additional citations forverification. Please helpimprove this article byadding citations to reliable sources. Unsourced material may be challenged and removed.
Find sources: "Opaque data type" – news ·newspapers ·books ·scholar ·JSTOR
(December 2011) (Learn how and when to remove this message)

Incomputer science, anopaque data type is adata type whose concretedata structure is not defined in aninterface. This enforcesinformation hiding, since itsvalues can only be manipulated by callingsubroutines 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 calledtransparent.[1] Opaque data types are frequently used to implementabstract data types.

Typical examples of opaque data types includehandles forresources provided by anoperating system toapplication software. For example, thePOSIX standard for threads defines anapplication programming interface based on a number of opaque types that representthreads orsynchronization primitives likemutexes orcondition variables.[2]

Anopaque pointer is a special case of an opaque data type, a datatype that is declared to be apointer to arecord ordata structure of some unspecified data type. For example, thestandard library that forms part of the specification of theC programming language provides functions forfileinput and output that return or take values of type "pointer toFILE" that represent file streams (seeC file input/output), but the concrete implementation of the typeFILE is not specified.[3]

Uses in various languages

[edit]

Some languages, such asC, allow the declaration of opaquerecords (structs), whose size and fields are hidden from the client. The only thing that the client can do with an object of such a type is to take itsmemory address, to produce anopaque pointer.

If the information provided by the interface is sufficient to determine the type's size, then clients can declarevariables,fields, andarrays of that type, assign their values, and possibly compare them for equality. This is usually the casefor opaque pointers.

In some languages, such asJava, the only kind of opaque type provided is the opaque pointer. Indeed, in Java (and several other languages) records are always handled through pointers.

Some languages allow partially opaque types, e.g. a record which has somepublic fields, known and accessible to all clients, and somehidden fields which are not revealed in the interface. Such types play a fundamental role inobject-oriented programming.

The information which is missing in the interface may be declared in itsimplementation, or in another "friends-only" interface. This second option allows the hidden information to be shared by two or more modules.

See also

[edit]

References

[edit]
  1. ^Friedman, Daniel P.;Wand, Mitchell;Haynes, Christopher T. (2001).Essentials of Programming Languages (2nd ed.). MIT Press. p. 42.ISBN 978-0-262-06217-6.
  2. ^Butenhof, David R. (1997).Programming with POSIX Threads. Addison-Wesley. p. 31.ISBN 978-0-201-63392-4.
  3. ^Kernighan, Brian W.;Ritchie, Dennis M. (1988).The C Programming Language (2nd ed.). Prentice Hall.ISBN 0-13-110362-8.
Uninterpreted
Numeric
Reference
Text
Composite
Other
Related
topics
Retrieved from "https://en.wikipedia.org/w/index.php?title=Opaque_data_type&oldid=1287471965"
Categories:
Hidden categories:

[8]ページ先頭

©2009-2026 Movatter.jp