正在加载图片...
look for a method to handle the reque lest and then invoke the method on the argumen " Making " an object message handler-each instance needs a new message handler to inherit the state information and methods of the specified class. The messag handler is not a full"object instance"in our system; the message handler needs to be part of an instance object (or part of another message handler that is part of an instance object). All procedures that define classes should take a self pointer( pointer to the enclosing instance)as the first argument "Creating "an object -the act of creation does three things it makes a new instance of the object; it makes and sets the message handler for that instance; and finally it INSTALL'S that new object into the world Installing "an object -this is a method in the object, by which the object can initialize itself and insert itself into the world, by connecting itself up with other related objects in the world Let's look at these different elements in a bit more detail Classes and instances Here is the template for a class definition in our object system. This is quite similar to the one introduced in lecture, but we have cleaned up the interface a little bit to make things easier to read (define (type self argl arg2 argn (let ((superl-part (superl self args) (super2-part (super2 self args) other superclass other local state (make-handle type (make-methods message-name-2 method-2 other messages and me thods superl-part super2-part ..)) That form is a little mystifying(we have put some terms in italics to indicate that these would be replaced by specific instances), so let,'s look at an example. In our simulation almost everything is going to have a name, thus let,'s create a named-object class (def (named-object self name) let ((root-part (root-object self)))look for a method to handle the request and then invoke the method on the arguments. “Making” an object message handler – each instance needs a new message handler to inherit the state information and methods of the specified class. The message handler is not a full “object instance” in our system; the message handler needs to be part of an instance object (or part of another message handler that is part of an instance object). All procedures that define classes should take a self pointer (a pointer to the enclosing instance) as the first argument. “Creating” an object – the act of creation does three things: it makes a new instance of the object; it makes and sets the message handler for that instance; and finally it INSTALL’s that new object into the world. “Installing” an object – this is a method in the object, by which the object can initialize itself and insert itself into the world, by connecting itself up with other related objects in the world. Let’s look at these different elements in a bit more detail. Classes and Instances Here is the template for a class definition in our object system. This is quite similar to the one introduced in lecture, but we have cleaned up the interface a little bit to make things easier to read: (define (type self arg1 arg2 ... argn ) (let ((super1-part (super1 self args) (super2-part (super2 self args) other superclasses other local state ) (make-handler type (make-methods message-name-1 method-1 message-name-2 method-2 other messages and methods ) super1-part super2-part ...))) That form is a little mystifying (we have put some terms in italics to indicate that these would be replaced by specific instances), so let's look at an example. In our simulation, almost everything is going to have a name, thus let's create a named-object class: (define (named-object self name) (let ((root-part (root-object self)))
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有