-
Enhancement
-
Resolution: Duplicate
-
P4
-
None
-
6
-
x86
-
windows_xp
A DESCRIPTION OF THE REQUEST :
Suppose you have a class called Component with 100 methods and 100 subclasses. At the present time, if you want to decorate Component with some additional behavior or information, you must create an interface (that you probably don't want to support in other use cases) with every method in Component and then invoke each method from the decorator class. Now the decorator object wraps the Component instance and can be extended.
JUSTIFICATION :
Manual delegation is painful.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Would be interesting if you could decorate a class in the language. A very limited way of creating decorators could be added to the language to potentially great effect and without any of the drawbacks associated with multiple inheritance:
class Component { }
class SecureComponent decorates Component
{
}
SecureComponent may not extend another class and may not specify a constructor. The Component instance passed in to the default constructor created by the compiler (SecureComponent may only be invoked by new SecureComponent(Component)) is automatically delegated to through a synthetic internal interface known only to the VM and available through super (as if Component were the superclass, which is also reflected in the type of SecureComponent). Now additional data and functionality can be added to the SecureComponent. Note that this is NOT multiple inheritance. Component has only one superclass. SecureComponent also has only one (articificial, synthetically emulated) superclass.
ACTUAL -
No such feature exists.
CUSTOMER SUBMITTED WORKAROUND :
Delegate all calls through an unwanted interface.
Suppose you have a class called Component with 100 methods and 100 subclasses. At the present time, if you want to decorate Component with some additional behavior or information, you must create an interface (that you probably don't want to support in other use cases) with every method in Component and then invoke each method from the decorator class. Now the decorator object wraps the Component instance and can be extended.
JUSTIFICATION :
Manual delegation is painful.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Would be interesting if you could decorate a class in the language. A very limited way of creating decorators could be added to the language to potentially great effect and without any of the drawbacks associated with multiple inheritance:
class Component { }
class SecureComponent decorates Component
{
}
SecureComponent may not extend another class and may not specify a constructor. The Component instance passed in to the default constructor created by the compiler (SecureComponent may only be invoked by new SecureComponent(Component)) is automatically delegated to through a synthetic internal interface known only to the VM and available through super (as if Component were the superclass, which is also reflected in the type of SecureComponent). Now additional data and functionality can be added to the SecureComponent. Note that this is NOT multiple inheritance. Component has only one superclass. SecureComponent also has only one (articificial, synthetically emulated) superclass.
ACTUAL -
No such feature exists.
CUSTOMER SUBMITTED WORKAROUND :
Delegate all calls through an unwanted interface.
- duplicates
-
JDK-4191243 Method forwarding - Subclassing without subtyping
-
- Closed
-