CS212 Exams
Spring 1999 - Final

Solution to Object Oriented Programming

WARNING: You should seriously try to answer this question before looking at the solution -- it's just a good study skill. Also, some answers on this page may be more brief than you would want to put down in an actual exam. If you want any type of partial credit, you should write more than just the solution.


(defclass <counted-container> (<container>)
  (count :type <integer>
         :accessor count
         :initarg :count
         :initvalue 0))


(defmethod (transfer (obj <contained>)
                     (source <container>)
                     (target <counted-container>))
  (call-next-method)
  (unless (eq? source target) (inc! (count target))))


(defmethod (transfer (obj <contained>)
                     (source <counted-container>)
                     (target <container>))
  (call-next-method)
  (unless (eq? source target) (dec! (count source))))

Question

Return to CS 212 Final - Spring 1999