In this brief step-by-step construction of object systems in Scheme, we have only illustrated some fundamental concepts of object-oriented programming languages. As always in language design, there is a world of possibilities to explore, variations on the same ideas, or extensions of these ideas.
Here is just a (limited/arbitrary) list of features and mechanisms that you will find in some existing object-oriented programming languages, which were not covered in our tour, and that you may want to try to integrate in the object system. It is—
Visibility for methods: public/private
Declare methods that override a method in a superclass: override
Declare methods that cannot be overriden: final
Declare methods that are expected to be inherited: inherit
Augmentable methods: inner
Interfaces: sets of messages to understand
Protocol to check if an object is instance of a class, if a class implements an interface, ...
Proper initialization protocol with superclasses, named initialization attributes
Classes as objects, metaclasses, ...
compute fields offset for direct field access
vtables & indices for direct method invocation
We now only briefly outline two mechanisms, interfaces and mixins, as well as their combination (ie. using interfaces in the specification of mixins).
(interface (superinterface-expr ...) id ...)
(CLASS* super-expr (interface-expr ...) decls ...)
(define positionable-interface (interface () get-pos set-pos move-by)) (define Figure (CLASS* Root (positionable-interface) ....))
> (implements? Figure positionable-interface) #t
A mixin is a class declaration parameterized over its superclass. Mixins can be combined to create new classes whose implementation sharing does not fit into a single-inheritance hierarchy.
(define (foo-mixin cl) (CLASS cl (....) (....))) (define (bar-mixin cl) (CLASS cl (....) (....))) (define Point (CLASS () ....)) (define foobarPoint (foo-mixin (bar-mixin Point))) (define fbp (foobarPoint 'create)) ....
(MIXIN (interface-expr ...) decl ...)