Mon 25 Oct 2004 08:53:29 PM UTC, original submission:
Proposed syntax to allow automatic delegation in the field section of a class :
TypeName field proxies (TypeName)+;
Rational : a delegate has nothing to do with class/interface inheritance.
==> It has nothing to do in the class definition line (class A implements I1
delegates ...)
Rational : a delegate is really an association
==> it has to appear as a field declaration.
rational : a delegate must have a name so that it can be used to overload a
method or do other stuff
==> a delegate is really a field and has a TypeName and a field name
Example :
---
public interface I1 {
sub f();
}
public interface I2 {
sub g();
}
public Impl implements I1, I2 {
public sub f() { /* implementation follows */ }
public sub g() { /* implementation follows */ }
}
public interface I3 {
sub h();
}
public A implements I1, I2, I3 {
private Impl impl proxies I1, I2; // the delegation
/* equivalent to
sub f() { impl.f(); }
sub g() { impl.g(); }
*/
public sub h() { /* implementation follows */ }
}
---
The delegation field 'impl' forward the implementation for all methods defined
in I1 and I2.
It is always possible to overload a method implemented by 'impl'.
Example :
---
public A implements I1, I2, I3 {
private Impl impl proxies I1, I2; // the delegation
/* method f() is automatically implemented by impl */
public sub g() { /* do stuff / / can call impl.g() */ }
public sub h() { /* impl follows */ }
}
|