Lecture of 12 February 1996

Homework Problem discussion

Button Classes and Behavior

Recall the toggle class with method switch we discussed previously:
define class <toggle> (<object>) slot value :: <boolean>, init-value: #f; end class <toggle>; define method switch (t :: <toggle>) t.value := ~ t.value; end switch;
Consider further the following button class and its method press:
define class <button> (<object>) slot action :: <function>, init-keyword: action:; slot object :: <object>, init-keyword: object:; end class <button>; define method press (b :: <button>) b.action (b.object); end method press;
What will happen if we evaluate each of the following:
define variable t = make (<toggle>); define variable b = make (<button>, action: switch, object: t); press (b); t; press (b); t;
Note how collecting together an action and object into a button provides an extremely general mechanism for issuing commands from a button.

Since switch is a generic function, what will happen to the button if I were to redefine the switch method for toggles to have some other behavior? Would the button reflect this change or not?

Inheritance

Inheritance Benefits

Polymorphism - What is it?

Is inheritance costly?

When should one subclass?

Specialization
This is the normal justification for creating a subclass. I have a window class, but now I need a special kind of window called a menu.
Many problems present choices and no clear-cut inheritance structure.
Specification
Budd notes that some classes, which he calls specification classes, are abstract, and are provide interface specifications for concrete classes that will be derived from them. I think again of the <collection> class of Dylan and some of its subclasses like <mutable-collection> and <sequence>. These classes do not have direct instances.
Combination
This is employed in multiple inheritance systems to combine the features of two dissimilar classes. The example of pg. 95 shows TeachingAssistant being derived from both Teacher and Student.
A common type of combination is the use of mix-in classes, which derives its name from Steve's Ice Cream Parlor in Somerville Massachussetts which would mix-in various goodies (such as chocalate chips, Reese's pieces, Gummy Bears, etc.) with ice cream. A mix-in class provides some specific capability that complements the behavior of any class that derives from it. Consider a class Displayable that might provide a specific behavioral interface, and a class Counter. We might create DisplayableCounter by deriving from both of these classes.

Composition vs. Construction

I prefer to discuss this issue in terms of inheritance and aggregation, the mechanisms that are employed.
This document is copyright 1996 by Joseph N. Wilson.