This is the mail archive of the
kawa@sourceware.org
mailing list for the Kawa project.
Re: abstract classes
- From: Per Bothner <per at bothner dot com>
- To: Robert Nikander <nikander at mercedsystems dot com>
- Cc: Kawa List <kawa at sources dot redhat dot com>
- Date: Wed, 22 Feb 2006 12:05:16 -0800
- Subject: Re: abstract classes
- References: <009AA198-3C01-4319-8404-40B9DC7DBC7C@mercedsystems.com>
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/