Reminder: Plagiarism
will not be tolerated. You may not copy sentences from
web pages, or anywhere. If you use text from anywhere, you must do
both the following: use quotation marks or indentation to
indicate very clearly that someone else wrote this text, and provide a
citation immediately before or after the text that is copied.
Languages have various mechanisms for making ADT function names visible. For example in ML:
Implementation parts typically contain completely private auxiliary functions that are not declared in the public signature.- pqstruct.onil;
val it = wrap [] : pqstruct.pq
- open pqstruct;
- onil;
val it = wrap [] : pq
ADTs provide "representation independence" (better called implementation independence) to their consumers. Hiding the concrete implementation of the type is crucial for this. ML is poorly designed in that the concrete implementation is not completely hidden. In the example above, the wrapper wrap is visible to users of the ADT.
The same signature can have multiple implementations. These may
differ, for example, on efficiency. Remember all the data structures
you know for sets.
Traditional abstract data types only allow the "public" and "private" possibilities.
The visibilities "friend" and "protected" take into account the role
of classes as modules of separate implementation and compilation.
Most concrete types are pure. For example, no operation on integers actually modifies an integer. Instead, all the operations like + produce fresh outputs.
An updatable ADT is one where some operations actually change values
of the ADT. For example, suppose we had an operation called pop that
took a priority queue as argument and modified it by removing the highest-priority
item. This operation would be impure and the whole ADT would then
be impure also.
A package has a public signature and a private implementation, like an ADT. The difference is that a package can simultaneously provide many types, many specific values, and many operations.
This increases flexibility and allows mutually dependent types but loses the analogy with concrete data types.
Packages preserve the crucial ADT idea of "information-hiding." Details that a user does not need to know are not visible to him.
Packages are best-known in Ada. ML signatures and structures are in fact packages also. Ada and ML both provide parametrized ADTs and packages.
One important use for packages is as units of separate compilation.
All the types in a package typically provide related functionality and
are implemented by the same person or team, so it is reasonable for the
classes in a package to have access to each other's implementation, i.e.
to all the state variables and methods of each other.