The question was:
In flashing-balls.rkt, the code for add-to-scene in FlashingBall% duplicates some of the code for add-to-scene in Ball%. Eliminate this by using super.
There are a number of ways to do this. Here's how I did it:
(field [color "red"]) (define/public (add-to-scene s) (place-image (circle radius (if selected? "solid" "outline") color) ;;; <---- changed line x y s))
(inherit-field color) ;; -> Void ;; EFFECT: rotate the list of colors, and reset time-left (define (change-colors) (set! colors (append (rest colors) (list (first colors)))) ;; put desired color into 'color' field (set! color (first colors)) ; <--- new line (set! time-left color-change-interval)) ;; Scene -> Scene ;; RETURNS: a scene like the given one, but with the flashing ball ;; painted on it. ;; EFFECT: decrements time-left and changes colors if necessary (define/override (add-to-scene s) (begin (if (zero? time-left) (change-colors) (set! time-left (- time-left 1))) ;; (place-image ;; (circle radius ;; (if selected? "solid" "outline") ;; (first colors)) ;; x y s) (super add-to-scene s) ; <-- call to super replaces ; duplicated code ))
Last modified: Wed Nov 18 15:03:03 Eastern Standard Time 2015