Object-Oriented Programming in

Common lisp







Figure 1 Standard Method Combination



;; define the class

(defclass triangle ()

((height :initarg :height :accessor height)

(base :initarg :base :accessor base)))



;;; methods roles; around, before, primary and after



(defmethod area :around ((object triangle))

(format t "Good!, We will start . . .~%")

(call-next-method))



(defmethod area :before ((object triangle))

(format t "Calculating the area of a triangle is an elementary problem encountered often in many different situations. The best known and simplest formula is: area = (b*h)/2 ~%"))



(defmethod area ((object triangle))

(format t "Calculating area . . .~%")

(format t "Area = ~a~%" (float (/ (* (base object) (height object)) 2))))



(defmethod area :after ((object triangle))

(format t "well done!, the infomation were: base= ~a and the height= ~a~%" (base object) (height object)))



;; create an object

(defparameter *my-triangle* (make-instance 'triangle :height 5.5 :base 2))





;; finally call the method

(area *my-triangle*)

