[ Table of Contents ] [ Prev ] [ Chapter Overview ] [ Glossary/Index ]
As usual, we begin with some self-test questions. (Answers are listed below in
Click Q#-# to see answer
||What is the Ada term for a hierarchy of types, where each descendant type
inherits properties from its parent?
||What are tagged types used for?
||When reading the declaration of a tagged type operation, how can you tell
whether it is a classwide operation or a dispatching operation?
||When you program a call to a dispatching operation, what determines
whether it will be dispatched statically (at compile time) or dynamically (at run time)?
||What are the names of the three predefined procedures that can be
overridden, providing extra control to the programmer creating a controlled type?
||What are some of the advantages of using inheritance and dynamic
Key points of this chapter
- An Ada derivation class of tagged types is used to build a hierarchy of types related by
inheritance. A convenient way to organize things is to use a child package to declare each
new type derived from a previous type declared in the parent package. (Ada keeps separate
the concepts of module and type.)
- Each new tagged type in the hierarchy inherits both a record structure and a set of
operations from its parent type. The new type may extend both the data structure (with new
record components) and/or the functionality (with new operations). It may also override
old operations with new versions.
- Every operation of one of the types in the hierarchy is either a classwide operation or
a dispatching operation. For dispatching operations, the dispatching occurs either
statically (at compile time) or dynamically (at run time) depending on the nature of the
controlling actual parameter declared in the client code.
- The client code may create objects of types in the hierarchy either statically (via
declarations) or dynamically (via allocators that create access values).
- When such objects are created, they are automatically initialized, using any default
values created in the type declaration. The objects automatically go out of existence when
the units that create them (or their access types) reach the end of execution.
- The programmer can achieve extra control over the initialization, assignment and
finalization processes by deriving the hierarchy of tagged types from the Controlled or
Limited_Controlled types exported by the package, Ada.Finalization.
Answers to Questions
||More reuse of software modules,
reduced demands for testing, and less copying and re-compiling.
||Initialize, Adjust and Finalize are the three
overridable procedures used in constructing controlled types.
||If the controlling actual parameter in
the client code is of a definite type, static dispatching occurs. If the controlling
actual parameter in the client code is of a classwide type, dynamic dispatching occurs.
||If the formal controlling parameter is of a
classwide type, the operation is a classwide operation. If the formal controlling
parameter is a definite type, the operation is a dispatching operation.
||Tagged types make it possible to create a
derivation class hierarchy with "type extension" and support for dynamic (run
||The term "derivation
class" refers to an Ada implementation of a hierarchy of types related via
[ Click here to return
to questions ]
This chapter has provided an introductory discussion of the classification style of
object oriented programming, as done in Ada, along with several example programs
illustrating relevant techniques. Key terms included in the Glossary/Index are:
The next chapter provides an introductory discussion of concurrency and
synchronization, as done in Ada.
[ Back to top of page ] [ Prev ] [ To next chapter ]