Previous: , Up: methods concrete   [Contents][Index]


7.1.3 Overriding methods

When a hierarchy of record–types is defined: the sub–types can override the super–type’s concrete methods by defining methods with the same name. Example:

(define-record-type <super>
  (method (doit)
    1))

(define-record-type <sub>
  (parent <super>)
  (method (doit)
    2))

(define (super-fun {O <super>})
  (.doit O))

(define (sub-fun   {O <sub>})
  (.doit O))

(define O
  (new <sub>))

(super-fun O)   ⇒ 1
(sub-fun   O)   ⇒ 2

The method of the super–type is still accessible if we “see” the object instance through the super–type’s type specification.

The sub–type’s method is in no way limited by the super–type’s method: the two methods are allowed to have completely different type signatures.