On this page:
6.1 Predicates and Contracts
class-or-interface/ c
object-provides/ c
class-provides/ c
mixin-provides/ c
object/ c
class/ c
mixin/ c
6.2 Mixins
ensure-interface
6.3 Methods
send+
send-each

6 Classes and Objects

 (require (planet cce/scheme:6:0/class))

This module provides tools for classes, objects, and mixins.

6.1 Predicates and Contracts

Recognizes classes and interfaces.

Recognizes objects which are instances of all the given classes and interfaces.

Recognizes classes which are subclasses (not strictly) and implementations, respectively, of all the given classes and interfaces.

(mixin-provides/c [super-expr ...] [sub-expr ...])
Function contract for a mixin whose argument is the parent class c% matching (class-provides/c super-expr ...) and whose result matches (class-provides/c c% sub-expr ...).

(object/c spec ...)  flat-contract?
  spec : class-or-interface/c
(class/c spec ...)  flat-contract?
  spec : class-or-interface/c
(mixin/c [super-expr ...] [arg-expr ...] [sub-expr ...])
Deprecated: These forms have been renamed to object-provides/c, class-provides/c, and mixin-provides/c above to make room for more expressive class, object, and mixin contracts that may be developed in scheme/class using the simpler names.

The middle clause of mixin/c has been removed in mixin-provides/c because mixins rarely need extra arguments, and class initialization arguments are usually the best way to provide them.

6.2 Mixins

(ensure-interface i<%> mx c%)  (class-provides/c c% i<%>)
  i<%> : interface?
  mx : (mixin-provides/c [] [i<%>])
  c% : class?
Returns c% if it implements i<%>; otherwise, returns (mx c%).

6.3 Methods

(send+ obj [message arg ...] ...)
Sends each message (with arguments) to obj, then returns obj.

Examples:

  (define c%
    (class object%
      (super-new)
      (define/public (say msg) (printf "~a!\n" msg))))
  > (send+ (new c%) [say 'Hello] [say 'Good-bye])

  Hello!

  Good-bye!

  #(struct:object:c% ...)

(send-each objs message arg ...)
Sends the message to each object in the list objs, returning (void).

Examples:

  (define c%
    (class object%
      (super-new)
      (init-field msg)
      (define/public (say to) (printf "~a, ~a!\n" msg to))))
  > (send-each
     (list (new c% [msg 'Hello])
           (new c% [msg 'Good-bye]))
     say 'World)

  Hello, World!

  Good-bye, World!