This is the mail archive of the
kawa@sources.redhat.com
mailing list for the Kawa project.
Re: how to define constructor methods in Scheme?
- From: Per Bothner <per at bothner dot com>
- To: "Hoehle, Joerg-Cyril" <Joerg-Cyril dot Hoehle at t-systems dot com>
- Cc: kawa at sources dot redhat dot com, Chris dot Dean at sokitomi dot com
- Date: Tue, 18 Nov 2003 13:19:28 -0800
- Subject: Re: how to define constructor methods in Scheme?
- References: <9F8582E37B2EE5498E76392AEDDCD3FE0808705D@G8PQD.blf01.telekom.de>
Hoehle, Joerg-Cyril wrote:
The goal is to interface with existing Java components. I need to write classes that interface to ("implement/extend") given Java interfaces, like the following code does in Java.
Therefore I believe I need Kawa's module-extends.
define-simple-class supports inheritance.
While you can use module-extends to implement classes with inheritance,
the module facility has somewhat different goals, and because if that
the implementation is more likely to change. The goal of
define-simple-class is to define a Java class in a predictable manner,
so if you want to interface with existing Java classes it is preferable.
I do have plans to enhance define-simle-class in the relatively near future.
Neither mechanism supports non-default constructors yet. It relatively
high on the list of things to do.
Until Kawa has better support for constructors, I suggest using separate
helper objets, and making the new object a proxy for the former.
Using Java syntax, instead of:
public class Foo extends Bar
{
public Foo(int arg) { super(arg); }
public Object method (int args)
{ return something(super.method(args)); }
}
do:
public class Foo extend Bar
{
private Bar helper;
public Foo makeFoo(int arg) { helper = new Bar(arg); }
public Object method (int args)
{ return something(helper.method(args)); }
}
This is pretty ugly and fragile. It only works if Bar has a
default constructor. The Foo object contains all the fields
of Bar, though it instead uses the corresponding fields of helper.
But hopefully we'll get a cleaner solution soon.
--
--Per Bothner
per@bothner.com http://per.bothner.com/