Lecture overview -- Keyboard shortcut: 'u'  Previous page: A general pattern of classes -- Keyboard shortcut: 'p'  Next page: A general pattern 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 7 : 11

Example of the general class pattern
The Point class redefined to comply with the general class pattern
(define (point x y)
 (let ((x x) 
       (y y)
      )
     
   (define (getx) x)

   (define (gety) y)

   (define (add p) 
    (point 
     (+ x (send 'getx p))
     (+ y (send 'gety p))))

   (define (type-of) 'point)
     
   (define (self message)
     (cond ((eqv? message 'getx) getx)
           ((eqv? message 'gety) gety)
           ((eqv? message 'add)  add)
           ((eqv? message 'type-of) type-of)
	   (else (error "Undefined message" message))))
     
   self))
point-class-all.scm
All necessary stuff to play with Point.
point-dialogue
A sample construction and dialogue with point.