[plt-scheme] class.ss inheritance

From: Neil W. Van Dyke (neil at neilvandyke.org)
Date: Tue Mar 18 23:16:23 EST 2003

Robby Findler <robby at cs.uchicago.edu> writes at 20:36 18-Mar-2003 -0600:
> I think that what you want are mixins. They are functions that consume
> a class and produce a class derived from the input, like this:

Excellent!  Followup question: is the idiomatic pairing of mixin and
interface shown below the way to go?

(define uri% (class* object% () ...))

(define hierarchical-uri<%> (interface () ...))
(define (hierarchical-uri-mixin %)
  (class* % (hierarchical-uri<%>) ...))

(define server-authority-uri<%> (interface () ...))
(define (server-authority-uri-mixin %)
  (class* % (server-authority-uri<%>) ...))

(define http-uri%
  (class* (hierarchical-uri-mixin (server-authority-uri-mixin uri%)) ()
    ...))

(define u (make-object http-uri%))
(is-a? u server-authority-uri<%>)     ==> #t
(is-a? u hierarchical-uri<%>)         ==> #t

-- 
                                             http://www.neilvandyke.org/


Posted on the users mailing list.