This is the mail archive of the kawa@sourceware.org mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: abstract classes


Robert Nikander wrote:
Can one use define-simple-class to create abstract classes or interfaces?

I don't believe there is any support for it yet.


define-class does create an interface, but I think the associated
implementation class has to be non-static.

I guess the first issue is deciding on the appropriate syntax.
We could extend the keyword syntax:

(define-simple-class <MyClass> ()
  ((lookup key) :: <object> abstract: #t))

Slightly clunky, though workable. An alternative is some special <body>
that represents an abstract body:

(define-simple-class <MyClass> ()
  ((lookup key) :: <object>
    *abstract*)

A possible generalization is to support Beta's "inner" call,
which provides a mechanism to enforce contracts and other
before/after behavior:

(define-simple-class <MyClass> ()
  ((lookup key) :: <object>
    (do-preliminary-actions)
    (try-finally
      (INNER key) ;; call any sub-class overriding.
      (do-cleanup-actions))))

This can be implemented as:

class MyClass {
  public Object lookup (Object key) {
    doPreliminaryActions();
    try {
      return lookup$MyClass$inner(key);
    } finally {
      doCleanupActions();
  }
  protected abstract Object lookup$MyClass$inner (Object key);

If the method returns void, then the helper method could be
a non-abstract empty method.  This is what Beta does.  However,
Beta has some unusual-to-say-the-least properties that may
be harder to fit into an expression-oriented language.
--
	--Per Bothner
per@bothner.com   http://per.bothner.com/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]