CS200: Computer Science, Spring 2002
|
Notes: Friday 8 March 2002
Schedule
- Spring Break Reading: finish Part I of GEB
- 18 March: GEB Questions
- Friday, 25 March: Problem Set 6
Notes
Inheritance is using the definition of one class to make another class.(define (make-number n) (lambda (message) (cond ((eq? message 'value) (lambda (self) n)) ((eq? message 'add) (lambda (self other) (+ (ask self 'value) (ask other 'value)))))))) (define (ask object message . args) (apply (object message) object args))The class fraction inherits from number.(define (make-fraction numer denom) (let ((super (make-number #f))) (lambda (message) (cond ((eq? message 'value) (lambda (self) (/ numer denom))) ((eq? message 'get-denominator) (lambda (self) denom)) ((eq? message 'get-numerator) (lambda (self) numer)) (else (super message))))))
fraction is a subclass of number.
The superclass of fraction is number.
University of Virginia Department of Computer Science CS 200: Computer Science |
David Evans evans@virginia.edu Using these Materials |