Created
February 3, 2020 15:24
-
-
Save masatoi/45f8b5ad446b4fb6e1c0167737e57998 to your computer and use it in GitHub Desktop.
call-next-method復習
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defclass parent () ()) | |
(defclass child (parent) ()) | |
(defparameter p1 (make-instance 'parent)) | |
(defparameter c1 (make-instance 'child)) | |
(defgeneric say (self word)) | |
(defmethod say ((self parent) word) | |
(format t "~A says ~A~%" self word)) | |
(defmethod say ((self child) word) | |
(format t "In child. ") | |
(call-next-method)) | |
(say p1 "hoge") ; => #<PARENT {1006518C23}> says hoge | |
(say c1 "mage") ; => In child. #<CHILD {1006528C23}> says mage | |
(defmethod say ((self child) word) | |
(format t "In child. ") | |
(call-next-method self (string-upcase word))) | |
(say p1 "hoge") ; => #<PARENT {1006518C23}> says hoge | |
(say c1 "mage") ; => In child. #<CHILD {1006528C23}> says MAGE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment