Previous: Sorting Methods, Up: Inheritance [Contents][Index]
When a class <A> defines a getter, setter or accessor for one of its slots x, an accessor method specialized to class <A> is created. Accessor methods are special in that they always refer to a concrete class. When you subclass <A>, a new accessor method for x is created automatically, specialized to the subclass:
(define-class <A> () (x #:accessor x)) (define-class <B> (<A>)) (generic-function-methods x) ⇒ (#<<accessor-method> (<B>) 7faa66b5b1c0> #<<accessor-method> (<A>) 7faa66b5b240>)
Note, in particular, that the x accessor method specialized to <A> is not applicable to objects of class B:
(define o (make <B>)) (compute-applicable-methods x (list o)) ⇒ (#<<accessor-method> (<B>) 7faa66b5b1c0>)
As a consequence, an accessor doesn’t have a next-method. The fact that accessor methods always apply to concrete classes allows for extensive optimization.