Lecture overview -- Keyboard shortcut: 'u'  Previous page: A general pattern of classes with inheritance -- Keyboard shortcut: 'p'  Next page: The interpretation of  <kbd>self</kbd> -- Keyboard shortcut: 'n'  Lecture notes - all slides and notes together  slide -- Keyboard shortcut: 't'  Textbook -- Keyboard shortcut: 'v'  Help page about these notes  Alphabetic index  Course home  Lecture 8 - Page 9 : 11
Functional Programming in Scheme
Object-oriented programming in Scheme
An example of classes with inheritance

We sketch one of the favorite toy specializations of Point - ColorPoint

(define (color-point x y color)
 (let ((super (new-part point x y))
       (self 'nil))
   (let ((color color))
       
     (define (get-color)
       color)

     (define (type-of) 'color-point)
       
     (define (dispatch message)
       (cond ((eqv? message 'get-color) get-color)
             ((eqv? message 'type-of) type-of)
             (else (method-lookup super message))))
       
     (set! self dispatch))
     
   self))

A specialization of Point which is called ColorPoint.

y:/Kurt/Files/courses/prog3/prog3-03/sources/notes/includes/colorpoint-class-all.scmAll necessary stuff to play with ColorPoint.


y:/Kurt/Files/courses/prog3/prog3-03/sources/notes/includes/color-point-dialogueA sample construction and sample dialogue with ColorPoint.


Go to exerciseColor Point Extension