CLIM mail archive

[Prev][Next][Index][Thread]

Re: Reverse Inheritance of Accept Methods



    Date: Sun, 19 Sep 1993 08:19 EDT
    From: fischerm@darmstadt.gmd.de (Markus Fischer)

	    From: "Bruce R. Miller" <miller@cam.nist.gov>
	    Subject: Reverse Inheritance of Accept Methods (was: for Gestures for commands more than 1 arg?)


	    [deleted]

	    I have the following class hierarchy:

	    OBJECT
	      OBJECT-WITH-PARTS
		OBJECT-WITH-COMPONENTS
		  PACKAGE
		  MODULE
		MODULE-COLLECTION
		  CLASS
		  PACKAGE        
	    [and a few others]

	...
   	Alternatively, I suppose I could write an accept method that did
	    something like

	    (defmethod do-accept (class stream ...)
	      (loop for sub in (clos:class-direct-subclasses clos-class)
		    thereis (do-accept sub stream ...)))

	    (defmethod do-accept ('class stream ...)
	      <from hashtable>)

    Looping over all subclasses would not do the intended thing.

Agreed.

    Instead, you'll have to read in first the name of the class 
    (out of the list) and then read the object of that class.
    ie. like:

    (define accept (..)
      (let ((class (accept 'class)))
	    (object (accept `(object-of ,class)
     ..))

    Now, let's waste some net bandwidth:

Yeah! Why not a bit of user interface philosophising?!
It seems somehow unfair for the list to be alternating messages of the 
form :
  Message 2*N:  "How do I ...." or "What's wrong with ..."
  Message 2*N+1: answer from Scott (or Bill, or um the guy from Franz?..)
  etc.
Not that I'm complaining; I've done it & I've got more Q's up my sleeve!

    I've written some naive code that does what was outlined above.
    Hopefully, it's also the kind of thing you need (ie. if 
    I understood your question correctly).

Yep that's capturing a lot of what I'm after. 
Rather than relying on some implicit indication of what the instanciable
classes are, you have the user explicitly set up a subordinate
hashtable.   That's a word I was searching for the other day:
"Instanciable"  There's this heirarchy of classes, only some of which
are intended to be instanciated.  All of those that are instanciated
are things that the user would recognized.

Did you see my (own) reply to my previous message?  Your suggestions
are similar in many ways.

I found two intersting things about class inheritance, as seen via CLIM:

   [ ...This is Markus's code ..., my comments]
    ;;; The CLIM interface
    ;;; --------------------------------------------------------------------------------

    (define-presentation-method present (object (type namespace-object) stream 
						(view textual-view) &key)
      (format stream "~A ~A" type (slot-value object 'name)))

Now we can (present object 'namespace-object)
        or (present object '<any-class-inheriting-from-namespace-object>)

BUT if we want to have a particular printed representation for some subclass,
Say not "<type> <name>", but "<type> <unique-id>"
we've got to circumvent the inheritance by something like:

(define-presentation-method present (object (type namespace-object) stream 
						(view textual-view) &key)
   (do-present object stream))

(defmethod do-present ((object namespace-object) stream)
  (format stream "~A ~A" type (slot-value object 'NAME)))
Then
(defmethod do-present ((object other-namespace-object) stream)
  (format stream "~A ~A" type (slot-value object 'UNIQUE-ID)))

Back to Markus' accept method:
    (define-presentation-method accept ((type namespace-object) stream 
					(view textual-view) &key)
      (let* ((class-name (accept `(member ,@(map 'list #'clos:class-name
						 ;; this could also be "class-subclasses",
						 ;; but that's not CLOS-built-in
						 (clos:class-direct-subclasses 
                                           ;;;***  (clos:find-class 'namespace-object))))
						   (clos:find-class TYPE)))) ;**********
				 :prompt NIL
				 :stream stream))
	     (object-name (accept `(token-or-type ,(let ((list NIL))
						     (maphash #'(lambda (key val)
								  (declare (ignore val))
								  (push key list))
							      (namespace-objects class-name))
						     (nreverse list))
						  symbol)
				  :prompt NIL
				  :stream stream)))
	(or (namespace-object class-name object-name)
	    (setf (namespace-object class-name object-name) 
		  (make-instance class-name :name object-name :properties '(might-be useful))))))

The change allows us to inherit the accept method so
(accept 'namespace-object) works
but so does
(accept 'some-subclass-of-namespace-object)
In the latter case, we only choose from those instanciable classes derived from 
some-subclass-of-namespace-object, rather than all of them.

Aint Object Oriented wonderful?!? :>

    ;;; EOF


  bruce
  miller@cam.nist.gov
  

References:

Main Index | Thread Index