Lecture overview -- Keyboard shortcut: 'u'  Previous page: Example of the general class pattern -- Keyboard shortcut: 'p'  Next page: An example of classes with inheritance -- Keyboard shortcut: 'n'  Lecture notes - all slides together  Annotated slide -- Keyboard shortcut: 't'  Textbook -- Keyboard shortcut: 'v'  Alphabetic index  Help page about these notes  Course home    Object-oriented programming in Scheme - slide 8 : 11

A general pattern of classes with inheritance
The following shows a template of a function that serves as a subclass of another class
(define (class-name parameters)
 (let ((super (new-part super-class-name some-parameters))
       (self 'nil))
   (let ((instance-variable init-value)
         ...)
       
     (define (method parameter-list)
       method-body)
     ...
       
     (define (dispatch message)
       (cond ((eqv? message 'selector) method)
             ...
             (else (method-lookup super message))))
       
     (set! self dispatch))
     
   self))
object-class.scm
A simulation of the root of a class hierarchy.
class-template-functions-inh.scm
Accompanying functions for instantiation, message passing, and method lookup.