This site contains older material on Eiffel. For the main Eiffel page, see http://www.eiffel.com.

EXERCISES

E25.1 Arrayed stacks

Write in full the STACK class and its heir ARRAYED_STACK sketched in this chapter, using the "marriage of convenience" technique.

E25.2 Meta-taxonomy

Imagine 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 inheritance

Provide 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 examples

For each of the following cases, indicate which one of the inheritance kinds applies:

  • SEGMENT from OPEN_FIGURE.

  • COMPARABLE (objects equipped with a total order relation) inheriting from PART_COMPARABLE (objects with a partial order relation).

  • Some class from EXCEPTIONS.

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:

  • The ease of applying iterations to arbitrary action and test routines, chosen by the application.

  • Extendibility: the possibility of adding new iteration schemes to the library.

  • More generally, respect of object-oriented principles, in particular the idea that operations do not exist by themselves but only in relation to certain data abstractions.

E25.7 Module and type inheritance

Assume 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?

 


PREVIOUS SECTION