[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
- To: email@example.com (Jeffrey B Kane)
- Subject: Initialize-instance
- From: Steve Strassmann <firstname.lastname@example.org>
- Date: Mon, 6 Jul 1992 12:22:01 -0500
- Cc: info-mcl
>Date: Mon, 6 Jul 92 10:38:38 -0400
>From: email@example.com (Jeffrey B Kane)
>I have another couple of quick CLOS related questions. The first has to do
>with defining my own "initialize-instance" method for my classes. For my
>simplest example, I didn't need any parameters, so I tried:
>(defclass twindow (window)
> ((garbage :initarg :garbage ; holds some value that I might need
> :initform nil
> :accessor garbage)))
>(defmethod initialize-instance ((me twindow) &rest)
> (print "Hi, I'm initializing an instance of a twindow")
> (initialize-instance (coerce me window)))
Forget the coerce command, that's not what you want at all.
Here's two different ways to do this:
; This doesn't shadow the previous definition, it just runs BEFORE it.
; Also check out AFTER methods.
(defmethod initialize-instance :before ((me twindow) &rest rest)
(declare (ignore rest))
(print "Hi, I'm initializing an instance of a twindow"))
; This wraps AROUND the prevous definition. You can provide
; different args to CALL-NEXT-METHOD.
(defmethod initialize-instance :around ((me twindow) &rest rest)
(declare (ignore rest))
(print "Hi, I'm about to initialize an instance of a twindow")
(print "Hi, I just initialized an instance of a twindow"))
>As a second question, what is the prefered way of calling an inherited method.
>In object pascal I just call
>inherited old_method(var1 var2 var3);
>in C I need to explicitly call it using the class name:
>parentClass::old_method(var1 var2 var3);
>Am I doing it correctly in the above example, i.e.
>(initialize-instance (coerce me window)))
>[I'm trying to call the inherited initialize-instance]
As indicated above, you don't need to explicitly call it when you
use :before or :after methods. Within an :around method, you can
>I'm still looking for the CLOS tutorial book. I got the book
>"Understanding CLOS" but it seems that it is mostly a rehash of
>the specification with little insight into it's actual use.
>Too bad I can't park at Quantum Books :)
There's a garage under Quantum; I think you might be able to
get validate parking (this is in Cambridge, Mass., for you readers