Using AOP to add new methods to a class/interface

G

GiladHa

Hello,

Can AspectWerkz/any other AOP framework, be used to weave
new methods to an existing class/interface?

An example:
I have a class
class Worker implements IWork {
public void doWork(A a, B b, C c)
{
do something ....
}
}

which implements an interface:
interface IWork {
void doWork(A a, B b, C c);
}


Can I write an aspect which defines, for both interface and
class, a new method called mock_doWork, which
receives the same parameters.

class Worker implements IWork {
public void doWork(A a, B b, C c)
{ ....
}

public void mock_doWork(A a, B b, C c)
{ ....
}
}

and:
interface IWork {
void doWork(A a, B b, C c);
void mock_doWork(A a, B b, C c);
}



Thanks for your assistance,

Gilad Haimov
 
J

Johannes Schneider

Hello,

Can AspectWerkz/any other AOP framework, be used to weave
new methods to an existing class/interface? AspectJ:
<http://dev.eclipse.org/viewcvs/inde.../doc/progguide/semantics-declare.html#d0e6053>

[example]
Can I write an aspect which defines, for both interface and
class, a new method called mock_doWork, which
receives the same parameters.
class Worker implements IWork {
public void doWork(A a, B b, C c)
{ ....
}
public void mock_doWork(A a, B b, C c)
{ ....
}
}
public void Worker.mock_doWork(A a, B b, C c)
{ ....
}
}
and:
interface IWork {
void doWork(A a, B b, C c);
void mock_doWork(A a, B b, C c)
}
public void IWork.mock_doWork(A a, B b, C c);

Hmm. Looks simple. Didn't try it.


Johannes
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top