This final question asks you to consider a tricky issue in language design. We are not requiring you to actually implement your design. Nevertheless, we do expect you to think carefully about the issues involved and to give a careful description of the solution you come up with. Don't think that this is a straightforward exercise--designers of object-oriented languages are still arguing about it.
The major way in which TOOL is simpler than other object-oriented
languages is that each class has only one immediate superclass.
As illustrated with message-passing systems (lecture on March 19),
there are cases where it is convenient to have a class inherit
behavior from more than one kind of class.
This will involve some changes to TOOL. As a start, the syntax for define-class must be modified to accept a list of superclasses rather than a single superclass. Let's assume that define-class now takes a list of superclasses. For instance, going back to our original example about cats, we might have:
(define-class <fancy-house-cat> (<house-cat> <show-cat>))
This new class should inherit from both <house-cat> and <show-cat>. In general, when the new class is constructed, it should inherit methods and slots from all its superclasses (and their ancestors).
However, it's not obvious what inheritance should mean. For example, suppose we have a generic function eat and we define methods as follows:
(define-method eat ((c <house-cat>)) (print '(yum: I'm hungry))) (define-method eat ((c <show-cat>)) (print '(I eat only caviar)))
What should happen when we ask a fancy-house-cat (which is both a show-cat and a house-cat) to eat? More generally, what is the ``most specific method'' that should be used when a generic function is applied to its arguments, given that some of the arguments may have multiple superclasses? What are the new kinds of choices that arise? How should the language give the user the ability to control these choices? (Or maybe it shouldn't give the user this level of control.)
Check the 6.001 discussion forum for computer-ex-06
Look here
for information about the forum.
| |