Delegation proposal

Marek Kozieł develop4lasu at gmail.com
Sat Mar 14 10:02:59 PDT 2009


*AUTHOR: **Lasu aka Marek Kozieł*

*OVERVIEW*

FEATURE SUMMARY:
This change allow to delegate methods, interfaces and classes.

MAJOR ADVANTAGE:
It would be a first step for programmers to have something instead of
inheritance, allowing to write better code.

MAJOR BENEFITS:
Java looks incomplete without something so base as delegating. Others are:
Code more immune for changes(if interface changes, there will be not so much
to change, or I would say, changes will be on the right place, but not on
all projects)
Decreasing costs of code modification.
Explicit defining MethodModifiers


MAJOR DISADVANTAGE:
Changes cost.

ALTERNATIVES:
It's nothing that cannot be implemented in a simple way, but this change
does not increase delegation complex, unreadability, and costs of support
with each method.


*EXAMPLES*

SIMPLE EXAMPLE:
public abstract class ClassA implements InterfaceA {

  InterfaceA ia = ...;

  public delegate InterfaceA{
  return ia;
  }

}


ADVANCED EXAMPLE:
public abstract class ClassA implements InterfaceA {

  ClassSome cs = ... ; // ClassSome implements InterfaceA, InterfaceB,
InterfaceC

  Some some = ... ; // have the same methods from InterfaceA and InterfaceC
but do not implements them

  public delegate ClassSome exclude Object,InterfaceB{
  if (cs==null) return some;
  return cs;
  }

}


*DETAILS*

SPECIFICATION:
DelegationDeclaration:
  DelegationHeader DelegationBody

DelegationHeader:
  DelegationModifiersopt delegate MethodSets Excludeopt Throwsopt
DelegationDeclarator

DelegationModifiers:
  DelegationModifier
  DelegationModifiers DelegationModifier

DelegationModifier: one of
  Annotation public protected private abstract static final synchronized

Exclude:
  exclude MethodSets

MethodSets:
  MethodSet
  MethodSets, MethodSet

MethodSet: one of
  ClassOrInterfaceType InterfaceMemberDeclaration

DelegationBody:
  same with: MethodBody except ReturnStatement

ReturnStatement:
  return* Expression

return work in different way in delegation than in method.
For each method with ResultType(Type) it's interpreted:
  return (Expression).MethodIdentifier(ActualParameters);
For each method with ResultType(void) it's interpreted:
  (Expression).MethodIdentifier(ActualParameters);
  return;


*COMPILATION*:
Delegation is deployed to all methods that occur in 'delegate MethodSets'
and do not occur in Excludeopt.
All methods have modifiers: DelegationModifiersopt
Declared exception in Throwsopt are added to each method ExceptionTypeList.

TESTING:
Normal way.

LIBRARY SUPPORT:
No

REFLECTIVE APIS:
No changed.

OTHER CHANGES:
None.

MIGRATION:
No need.

COMPATIBILITY
All working programs will still work. New byte code is compatible with old
one.

*REFERENCES*
Delegation proposal:
http://lasu2string.blogspot.com/2009/03/delegation-proposal.html


-- 
Pozdrowionka. / Regards.
Lasu aka Marek Kozieł

http://lasu2string.blogspot.com/



More information about the coin-dev mailing list