


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



David Evans http://www.cs.virginia.edu/evans
CS150: Computer Science University of Virginia Computer Science
Lecture 23: Programming with Objects 2
http://www.cs.virginia.edu/forums/viewforum.php?f=
http://www.cs.virginia.edu/forums/viewtopic.php?t=
http://www.sportsline.com/collegebasketball/scoreboard
Lecture 23: Programming with Objects 3
Lecture 23: Programming with Objects 4
Lecture 23: Programming with Objects 5
Lecture 23: Programming with Objects 6
(ask Object Method)
Lecture 23: Programming with Objects 7
Lecture 23: Programming with Objects 8
Lecture 23: Programming with Objects 9
(define make-fraction (lambda (numerator denominator) (lambda (message) (cond ((eq? message 'value) (lambda (self) (/ numerator denominator)) ((eq? message 'add) (lambda (self other) (+ (ask self 'value) (ask other 'value))) ((eq? message ‘get-numerator) (lambda (self) numerator)) ((eq? message ‘get-denominator) (lambda (self) denominator)) )))))
Same as in make-number
Note: our add method evaluates to a number, not a fraction object (which would be better). Lecture 23: Programming with Objects 10
Lecture 23: Programming with Objects 11
Lecture 23: Programming with Objects 12
(define (make-fraction numer denom) (make-subobject (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 #f)))))
Lecture 23: Programming with Objects 19
Lecture 23: Programming with Objects 20
procedure for constructing objects in the
student inherits from person which inherits from mobile-object which inherits from physical-object which inherits from sim-object.
Lecture 23: Programming with Objects 21
Cabal Hall (^) Recursa
Alyssa P. Hacker
(make-place name) evaluates to an object that is an instance of the class place.
Lecture 23: Programming with Objects 22
Lecture 23: Programming with Objects 23