[racket] Overriding methods in Racket classes

From: Harry Spier (vasishtha.spier at gmail.com)
Date: Thu Jan 3 17:01:54 EST 2013

Dear list members,

In Racket is it possible to override a non-public method?

For example in the Racket Guide section 13 and 13.1 it gives this example:

(class object%
  (init size)                ; initialization argument

  (define current-size size) ; field

  (super-new)                ; superclass initialization

  (define/public (get-size)
    current-size)

  (define/public (grow amt)
    (set! current-size (+ amt current-size)))

  (define/public (eat other-fish)
    (grow (send other-fish get-size))))
. . .
. . .
(define picky-fish% (class fish% (super-new)
                      (define/override (grow amt)

                        (super grow (* 3/4 amt)))))

which works fine but some entity can still tell a fish to "grow"
outside the context of telling it to "eat" another fish.

Apologies if I've missed something obvious but I've just started going
through the Classes and Objects documentation.  I can see where you
can declare a method public and overridable, or public and not
overridable, but I don't see a declaration for a method to be private
to the outside world but public and overridable to its sub-classes.

Thanks,
Harry Spier

Posted on the users mailing list.