-
Enhancement
-
Resolution: Won't Fix
-
P4
-
None
-
1.2.0, 6
-
generic, sparc
-
generic, solaris_10
Name: dgC58589 Date: 01/15/98
Here is a suggestion a colleague of mine, Mike Kelly, that I like and would
support for the Java language at large. This is mostly transcribed from message
he sent decribing Delegation in Java.
The basic idea is this: a class may delegate any number of implementations;
a delegate is an expression evaluated WRT an instance of the delegating class.
In it's simplest form, the expression would simply be the name of an instance
variable.
The result is an delagate-based composition which allows delegating classes
to support interfaces which change without having to continually modify
the delegating class's implementation (both to trivially implement new
methods, and to remove methods no longer necessary). Besides making
development far more open to change, I think the reduction in code and
direct representation of such a common design technique would make a
system much more understandable.
Suggested syntax:
class <name>
[extends <class-name>]
[implements <interface-names> [using <expression> [, <interface-names>
using <expression> ...]]] {...}
A method in a delegating class would take precedence over a delegate
expression, and two or more delegate expressions which implement the
same interface (via inheritence) would have to be explicitly implemented
in the delegating class. A very simple example:
public interface IBase
{
public void base();
}
public interface IDerived
extends IBase
{
public void derived();
}
public class DerivedAdapter
implements IDerived using myDerivedDelegate
{
private IDerived myDerivedDelegate;
public DerivedAdapter(IDerived derived) { myDerivedDelegate = derived;
... }
public void base() { /* Implement 'better' than with simple delegation
*/ ... }
/* The following method is generated by the compiler:
public void derived() { myDerivedDelegate.derived(); } */
}
(Review ID: 23364)
======================================================================
Here is a suggestion a colleague of mine, Mike Kelly, that I like and would
support for the Java language at large. This is mostly transcribed from message
he sent decribing Delegation in Java.
The basic idea is this: a class may delegate any number of implementations;
a delegate is an expression evaluated WRT an instance of the delegating class.
In it's simplest form, the expression would simply be the name of an instance
variable.
The result is an delagate-based composition which allows delegating classes
to support interfaces which change without having to continually modify
the delegating class's implementation (both to trivially implement new
methods, and to remove methods no longer necessary). Besides making
development far more open to change, I think the reduction in code and
direct representation of such a common design technique would make a
system much more understandable.
Suggested syntax:
class <name>
[extends <class-name>]
[implements <interface-names> [using <expression> [, <interface-names>
using <expression> ...]]] {...}
A method in a delegating class would take precedence over a delegate
expression, and two or more delegate expressions which implement the
same interface (via inheritence) would have to be explicitly implemented
in the delegating class. A very simple example:
public interface IBase
{
public void base();
}
public interface IDerived
extends IBase
{
public void derived();
}
public class DerivedAdapter
implements IDerived using myDerivedDelegate
{
private IDerived myDerivedDelegate;
public DerivedAdapter(IDerived derived) { myDerivedDelegate = derived;
... }
public void base() { /* Implement 'better' than with simple delegation
*/ ... }
/* The following method is generated by the compiler:
public void derived() { myDerivedDelegate.derived(); } */
}
(Review ID: 23364)
======================================================================
- duplicates
-
JDK-6483595 No support for automatic delegation...
-
- Closed
-
- relates to
-
JDK-4191243 Method forwarding - Subclassing without subtyping
-
- Closed
-