This is the mail archive of the kawa@sources.redhat.com 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: how to define constructor methods in Scheme?


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/



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