Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] declare parents with delegate

Yes, that is the challenge, generate the methods when needed by delegating them to the delegate member. I know that aop (and AspectJ in particular) is not a generative programming tool, but this can be very useful, good for the reutilization (since one must not maintain synchronized the superclass with the subclass when the change in the former has nothing to do with the overriden methods in the latter) and it has a lot in common with the current provided static-crosscutting tools. It is easy to implement in AspectJ too, I feel.

Best regards.

Guntis Ozols wrote:

This idiom is great, too, but the question actually was slightly different.
Is there a shortcut for something like this:

class DatabaseMetaDataWrapper implements DatabaseMetaData {

   private DatabaseMetaData delegate;

   // constructor, some implemented methods here

   //===================== DELEGATE METHODS =====================
   public boolean allProceduresAreCallable() throws SQLException {
       return delegate.allProceduresAreCallable();
   }
   public boolean allTablesAreSelectable() throws SQLException {
       return delegate.allTablesAreSelectable();
   }
   // And so on and so on...
   // Problem #1: more than 500 useless lines
   // Problem #2: depends on java version!
   // Also want to advice some of the methods
}


It can be done by using an inter-type declaration on the Runnable
interface. This may sound crazy but what we are actually doing is making an
ITD on every implementer of the interface. The advantage of this approach
is that not only do we guarantee all methods are implemented but also if a
class provides its own implementation that will be used instead of the ITD.
This is why the idiom is often referred to as supplying default interface
method implementations.

public aspect MyAspect {

     declare parents : MyClass implements Runnable;

     public void Runnable.run () {
           // Default behaviour
     }

}

Matthew Webster
AOSD Project
Java Technology Centre, MP146
IBM Hursley Park, Winchester,  SO21 2JN, England
Telephone: +44 196 2816139 (external) 246139 (internal)
Email: Matthew Webster/UK/IBM @ IBMGB, matthew_webster@xxxxxxxxxx
http://w3.hursley.ibm.com/~websterm/


Santi Villalba <sdvillal@xxxxxxxx>@eclipse.org on 26/09/2004 11:22:55

Please respond to aspectj-users@xxxxxxxxxxx

Sent by:    aspectj-users-admin@xxxxxxxxxxx


To:    aspectj-users@xxxxxxxxxxx
cc:
Subject:    Re: [aspectj-users] declare parents with delegate


Hi,

It would be great if this feature is available some day, since I have
been missing it for a long time. I think it can be particularly useful
to do realizations of patterns like decorator or proxy.

I think that it can't be done using dynamic crosscutting. If I'm wrong,
please, tell me.

Best regards

guntiso@xxxxxxxxx wrote:

Hi,

AspectJ supports adding a superinterface onto a type,
with the declare parents form.

Is there a way to specify just a delegate instead of
missing (potentially hundreds of) methods?

Something like
declare parents:
  MyClass implements Runnable delegate MyClass.delegate

Any plans on this? Any tools?
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
http://dev.eclipse.org/mailman/listinfo/aspectj-users




Back to the top