|
||||
EXERCISESE25.1 Arrayed stacksWrite in full the STACK class and its heir ARRAYED_STACK sketched in this chapter, using the "marriage of convenience" technique. E25.2 Meta-taxonomyImagine the classification of kinds of inheritance were an inheritance hierarchy. What kind or kinds would it involve?
E25.3 The stacks of Hanoi(This exercise comes from an example used by Philippe Drix on the French GUE electronic mailing list, late 1995 and early 1996.) Assume a deferred class STACK with a procedure put to push an element onto the top, with a precondition involving the boolean-valued function full (which could also be called extendible; as you study the exercise you will note that the choice of name may affect the appeal of various possible solutions). Now consider the famous problem of the Towers of Hanoï, where disks are stacked on piles --- the towers --- with the rule that a disk may only be put on a larger disk.
Is it appropriate to define the class HANOÏ_STACK, representing such piles, as an heir to STACK? If so, how should the class be written? If not, can HANOÏ_STACK still make use of STACK? Write the class in full for the various possible solutions; discuss the pros and cons of each, state which one you prefer, and explain the rationale for your choice. E25.4 Functional variation inheritanceProvide one or more examples of functional variation inheritance. For each of them, discuss whether they are legitimate applications of the open-closed principle or examples of what the discussion called "disciplined hacking". E25.5 Classification examplesFor each of the following cases, indicate which one of the inheritance kinds applies:
E25.6 Where do iterators belong?Would it be a good idea to have iterator features (while_do and the like) included in classes describing the data structures on which they iterate, such as LIST? Consider the following points:
E25.7 Module and type inheritanceAssume
we devise a language with two kinds of inheritance: module extension and
subtyping. Where would each of the inheritance kinds identified in this chapter
fit?
|