[aspectc-user] changing the inheritance tree: adding parents to an already existing class
Olaf Spinczyk
Olaf.Spinczyk at informatik.uni-erlangen.de
Mon Jan 24 12:01:40 CET 2005
Hello Peter,
Peter Vandersteegen wrote:
> Hello,
>
> Recently I came into contact with aspectJ and its C++ counterpart: aspectC.
> In some projects I'm involved with, it can be useful to change the
> 'inheritance tree.'
> For example I mean you can add parents to an already existing class.
> (while using aspects of course)
>
> Now I wonder how this can be done in aspectC.
>
> I've found a java example to illustrate this behavior.
> In aspectJ you use " declare parents" to change the 'inheritance tree'
>
> public aspect FooRunnable{
> declare parents: Foo implements Runnable;
>
> public void Foo.run(){
> System.out.prinln("added a method to an already defined
> class");
> }
> }
>
> This example can also be found on:
> http://www-106.ibm.com/developerworks/java/library/j-aopsc/
>
> Can you please tell me if this example is done in aspectC?
> If not, can you please tell me if there are plans to include this
> behavior in aspectC?
>
> kind regards
>
> Peter
>
> ps. greet work building the aspectC language and its compiler.
>
>
>
>
> Peter Vandersteegen
> Ghent University, Dept. of Information Technology
> Sint-Pietersnieuwstraat 41, B-9000 Gent, Belgium
> WWW: http://photonics.intec.UGent.be
in AspectC++ this is called a "baseclass introduction":
#include "Runnable.h" // you need the definition of Runnable!
aspect FooRunnable {
public: // this is need to make the following intros public!
advice "Foo": baseclass (Runnable);
advice "Foo": void run () { ... }
};
(I didn't compile this code fragment, but it should work)
You can even go one step further in AspectC++ and define an abstract
aspect like this:
aspect TurnIntoRunnable {
pointcut virtual runnables() = 0;
public:
advice runnables () : baseclass (Runnable);
/* make only sense if all Runnables do the same ... */
advice runnables () : void run () { ... }
};
and in a derived aspect:
aspect FooRunnable {
pointcut runnables () = "Foo";
};
Best regards,
Olaf
More information about the aspectc-user
mailing list