[Ada Information Clearinghouse]
Ada '83 Rationale, Sec 7.9: Conclusion - Achieving Copies in Ada

"Rationale for the Design of the
Ada® Programming Language"

[Ada '83 Rationale, HTML Version]

Copyright ©1986 owned by the United States Government. All rights reserved.
Direct inquiries to the Ada Information Clearinghouse at adainfo@sw-eng.falls-church.va.us.

CHAPTER 7: Derived Types

7.9 Conclusion - Achieving Copies in Ada

7.9 Conclusion - Achieving Copies in Ada

Three main classes of entity are found in Ada programs:

  1. Objects
  2. Types
  3. Program units
The last class consists mainly of subprograms and packages. Nominally, it also includes tasks; although in certain respects tasks are closer to types and objects.

For each class of entity, the language provides a copying mechanism; that is, a mechanism by which we can create distinct replicas having similar properties:

class of entityreplication mechanism
(1) objects
(2) types
(3) program units
object declaration
type derivation
generic instantiation

Clearly, there are limits to this analogy since each replication mechanism is adapted to the class of entities to which it applies.

The replication mechanism offered by generic units is very powerful and can be used to replicate the contents of program units. Thus in section 7.3 it was shown that some aspects of type replication (not all, however) could be achieved by generic instantiation of a package that included the model type.

The generality of generic units certainly runs against a saying often heard in programming language design that there should be only one way of doing a given thing. Generic instantiation can even be used to achieve object replication, but it would be carrying matters to extremes to conclude from this that no simpler way should be provided. Consider thus

package CREATE is

and now we can replicate objects by generic instantiation:

package A                 is new CREATE;  -- creates A.OBJECT
package B                 is new CREATE;  -- creates B.OBJECT
package Z                 is new CREATE;  -- creates Z.OBJECT

But (obviously) replication of objects could be achieved in a simpler manner:


The awkwardness of the above example should be an indication of the limitations of the only one way principle. (Note also that we are in an inescapable circular situation since both ways imply an object declaration.) Generic instantiation can be used to replicate objects but it is not the most natural way. Similarly, although generic instantiation can be used to replicate types, derivation is a more natural and direct way.

To summarize this point, the design of Ada has provided replication mechanisms for each of the three main classes of entity: objects, types, and program units. Each of these mechanisms is adapted to the corresponding class of entity: it provides the natural way of replicating the corresponding entities. Being specialized, these mechanisms can also take advantage of specific aspects of the entities concerned. In the case of generic units these specific aspects correspond to parameterization. In the case of derived types the specific aspects correspond to the allowed explicit conversions.

Six major situations have been reviewed in which copying a type provides a natural solution for the problem considered:

The common characteristic of the above six situations is that in each of them there is a need to introduce a type that is a copy of another type. Without derivation, a variety of solutions and palliatives, most of them only partially satisfactory, would be required to solve these six problems. Furthermore many of these palliatives would involve manual copying and therefore raise severe issues of maintenance and configuration control. With derivation a unique - and elegant - mechanism is used to solve what is inherently a unique problem: the replication of a type.

Address any questions or comments to adainfo@sw-eng.falls-church.va.us.