;; This file contains excerpts from the textbook Concrete ;; Abstractions: An Introduction to Computer Science Using Scheme, by ;; Max Hailperin, Barbara Kaiser, and Karl Knight, Copyright (c) 1998 ;; by Brooks/Cole Publishing Company. This file may not be reproduced ;; or redistributed other than for use with that textbook. ;; Chapter 14: Object-Oriented Programming ;; 14.5 An Application: Adventures in the Imaginary Land of Gack (define-class 'thing named-object-class '(owner) '(owned? owner become-unowned become-owned-by)) (class/set-method! thing-class 'init (lambda (this name) (named-object^init this name) (thing/set-owner! this 'no-one))) (class/set-method! thing-class 'owned? (lambda (this) (not (equal? (thing/owner this) 'no-one)))) (class/set-method! thing-class 'owner (lambda (this) (thing/get-owner this))) (class/set-method! thing-class 'become-unowned (lambda (this) (thing/set-owner! this 'no-one))) (class/set-method! thing-class 'become-owned-by (lambda (this person) (thing/set-owner! this person)))