Created
June 29, 2022 22:35
-
-
Save juan-reynoso/c7c99b3dae0bec76807098d9d0c63123 to your computer and use it in GitHub Desktop.
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
;;;; The Standard Method Combination | |
(defclass book () | |
((name :accessor book-name | |
:initarg :book-name))) | |
;;; Create an object | |
(defparameter *book* (make-instance 'book | |
:book-name "The Art of the Metaobject Protocol")) | |
;;; This is the :around method | |
;;; The around method is run before anything else. | |
(defmethod open-this :around ((object book)) | |
(format t "Run before anything else. ~a ~%" (book-name object)) | |
;; In this case the next method is the before method | |
;; If you don't put (call-next-method) in the around method body | |
;; the before, primary and after methods will do not execute | |
(call-next-method)) | |
;;; This is the before method | |
;;; before-methods are called before the primary method | |
(defmethod open-this :before ((object book)) | |
(format t "Take out ~a book. ~%" (book-name object))) | |
;;; This is the primary method | |
;;; It performs bulk of the work | |
(defmethod open-this ((object book)) | |
(format t "Open ~a book. ~%" (book-name object))) | |
;;; This is the after method | |
;;; after-methods are called after the primary method | |
(defmethod open-this :after ((object book)) | |
(format t "Put ~a book in the backpack. ~%" (book-name object))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment