正在加载图片...
Our simulated world needs places(e.g. rooms or spaces) where interesting things will occur. The definition of the place class is shown below 1 i symbol - place (create-instance place name)) (define (place self name) (let ((named-part (named-object self name)) (container-part (container self)) exits 0)) (make-handler (make-methods EXITs (lambda exits EX工 (lambda(direction) (find-exit-in-direction exits direction)) ADD-EXIT (lambda(exit) (let ((direction (ask exit DIRECTION ))) (if (ask self 'EXIT-TOWArds direction) (error (list name "already has exit" direction)) set! exits (cons exit exits))) DONE))) container-part named-part))) If we look at the first and last lines of place, we notice that place inherits from two different classes: it has both an internal named-part and an internal container-part. If the place receives a message that doesn,'t match any of its methods, the get-method procedure will first check the container-part for the method, then use the named-part This is generally called"multiple inheritance, "which comes with a host of issues discussed briefly in lecture. You'll note that named-object and container only share one method of the same name, TYPE, and place overrides it. The TYPE method calls the type-extend procedure with both parent-parts. Retrieving the type of a place (define stata (create-place 'stata-center)) (ask stata TYPE) lue: (place named-object root container) You aren't guaranteed anything about the order of the type-descriptors except that the first descriptor in the list is the class that you instantiated to create the instance. You can also see that our place instances will each have their own internal variable exits, which will be a list of exit instances which lead from one place to another place In our object- oriented terminology, we can say the place class establishes a"has-a"relationship with the exit class(as opposed to the "is-a"relationship denoting inheritance). You should examine the objtypes. scm file to understand the definition for exits Mobile-thing classOur simulated world needs places (e.g. rooms or spaces) where interesting things will occur. The definition of the place class is shown below. (define (create-place name) ; symbol -> place (create-instance place name)) (define (place self name) (let ((named-part (named-object self name)) (container-part (container self)) (exits '())) (make-handler 'place (make-methods 'EXITS (lambda () exits) 'EXIT-TOWARDS (lambda (direction) (find-exit-in-direction exits direction)) 'ADD-EXIT (lambda (exit) (let ((direction (ask exit 'DIRECTION))) (if (ask self 'EXIT-TOWARDS direction) (error (list name "already has exit" direction)) (set! exits (cons exit exits))) 'DONE))) container-part named-part))) If we look at the first and last lines of place, we notice that place inherits from two different classes: it has both an internal named-part and an internal container-part. If the place receives a message that doesn't match any of its methods, the get-method procedure will first check the container-part for the method, then use the named-part. This is generally called "multiple inheritance," which comes with a host of issues as discussed briefly in lecture. You'll note that named-object and container only share one method of the same name, TYPE, and place overrides it. The TYPE method calls the type-extend procedure with both parent-parts. Retrieving the type of a place: (define stata (create-place 'stata-center)) (ask stata 'TYPE) ;Value: (place named-object root container) You aren't guaranteed anything about the order of the type-descriptors except that the first descriptor in the list is the class that you instantiated to create the instance. You can also see that our place instances will each have their own internal variable exits, which will be a list of exit instances which lead from one place to another place. In our object￾oriented terminology, we can say the place class establishes a "has-a" relationship with the exit class (as opposed to the "is-a" relationship denoting inheritance). You should examine the objtypes.scm file to understand the definition for exits. Mobile-thing class
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有