[ Table of Contents ] [ Prev ] [ Chapter Overview ] [ Glossary/Index ]
As usual, we begin with some self-test questions. (Answers are listed below in
reverse order.)
Self-Test
Questions
Click Q#-# to see answer |
Q5-1 |
What is the Ada term for a hierarchy of types, where each descendant type
inherits properties from its parent? |
Q5-2 |
What are tagged types used for? |
Q5-3 |
When reading the declaration of a tagged type operation, how can you tell
whether it is a classwide operation or a dispatching operation? |
Q5-4 |
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)? |
Q5-5 |
What are the names of the three predefined procedures that can be
overridden, providing extra control to the programmer creating a controlled type? |
Q5-6 |
What are some of the advantages of using inheritance and dynamic
dispatching? |
|
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 |
A5-6 |
More reuse of software modules,
reduced demands for testing, and less copying and re-compiling. |
A5-5 |
Initialize, Adjust and Finalize are the three
overridable procedures used in constructing controlled types. |
A5-4 |
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. |
A5-3 |
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. |
A5-2 |
Tagged types make it possible to create a
derivation class hierarchy with "type extension" and support for dynamic (run
time) dispatching. |
A5-1 |
The term "derivation
class" refers to an Ada implementation of a hierarchy of types related via
inheritance. |
|
[ Click here to return
to questions ] |
Wrap-up Discussion
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 ]