Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-dev] Possible?

Give this situation:

public class A
{
	private B m_b;
	
	public void method()
	{
		m_b = new B( "Test" );
		m_b.method();
	}
}

public class B extends D
{
	public B(String string)
	{
	}

	public void method()
	{
	}
}

public class C extends D
{
	public C(String string)
	{
	}

	public void method()
	{
	}
}

Is it possible to change A so that when it tries to do this:

		m_b = new B( "Test" );
		m_b.method();		
		
it actually effectively does this:

		m_b = new C( "Test" );
		m_b.method(); // calls C's method()		
	
In other words can I used AspectJ to substitute another class C
for class B (as long as it has the same inheritance model and public 
interface) without changing the original source code?


If the above is impossible, a related question is:

Can I create an aspect such that if there is a call to a method, that
method call 
is redirected to another object (that has a method of the same
signature) instead?

And then when that other object's method call is finished, the original
object's 
method's code is bypassed altogether?

Thanks,

Ted


Back to the top