source: branches/new-datamodel/playground/call-next-method.lisp

Last change on this file was 223, checked in by lgiessmann, 14 years ago

new-datamodel: added a sample file that handles "call-next-method" and the auxiliary methods (":before", "after" and "around")

File size: 1.4 KB
Line 
1(defclass Class-1 ()
2  ((value :initarg :value
3          :accessor value)))
4
5(defmethod set-value :before ((inst Class-1) value)
6  (format t ":before -> value is of type ~a~%" (type-of value)))
7
8(defmethod set-value ((inst Class-1) value)
9  (format t ": -> value is being set to ~a~%" value)
10  (setf (slot-value inst 'value) value))
11
12(defmethod set-value :after ((inst Class-1) value)
13  (format t ":after -> value was set to ~a~%" value))
14
15(defmethod set-value :around ((inst Class-1) value)
16  (format t ":around -> ???~%")
17  (call-next-method inst "123")) ;calls the :before method with the
18                                 ;arguments inst and "123"
19                                 ;if no arguments are passed the arguments
20                                 ;of the :around method are passed
21
22(defvar *inst* (make-instance 'Class-1))
23(set-value *inst* "val")
24;:around -> ???
25;:before -> value is of type (SIMPLE-ARRAY CHARACTER (3))
26;: -> value is being set to 123
27;:after -> value was set to 123
28
29
30(defclass Class-2 (Class-1)
31  ())
32
33(defmethod set-value ((inst Class-2) value)
34  (call-next-method) ;calls set-value of Class-1
35  (format t "(Class-2): -> value is being set to ~a~%" value)
36  (setf (slot-value inst 'value) value))
37
38(defvar *inst2* (make-instance 'Class-2))
39(set-value *inst2* "val2")
40;:around -> ???
41;:before -> value is of type (SIMPLE-ARRAY CHARACTER (3))
42;: -> value is being set to 123
43;(Class-2): -> value is being set to 123
44;:after -> value was set to 123
Note: See TracBrowser for help on using the repository browser.