Interface+抽象方法使用测试

项目里面使用spring,我不会配置(正在学),都是师兄配好了直接用。看到里面都有这么一句。

	@InjectSpring("xtglFacade")
	public abstract XtglFacade getXtglFacade();


这表示注入一个Facade吧,我也不懂。想弄明白是怎么回事,就自己写几个test玩儿,但是越写越糊涂了。如下:

TestA.java

package com.djwl.test.interfaceTest;

import java.util.UUID;

public class TestA {

	public TestA() {
		System.out.println("step7:constructorA");
	}

	public String getUUID() {
		System.out.println("step9");
		return UUID.randomUUID().toString().replaceAll("-", "");
	}
}



TestB.java
package com.djwl.test.interfaceTest;

public interface TestB {

	public TestA getTestA();
	
	public String test();
}



TestBImpl.java
package com.djwl.test.interfaceTest;

public abstract class TestBImpl implements TestB {

	public abstract TestB getTestB();
	
	public String test() {
		System.out.println("step2");
		String string = getTestB().getTestA().getUUID();
		System.out.println("step10");
		return string;
	}
}


TestC.java

package com.djwl.test.interfaceTest;

public class TestC extends TestBImpl {

	public TestC(){
		System.out.println("step4:constructorC");
	}
	
	public TestA getTestA() {
		System.out.println("step6");
		TestA testA = new TestA();
		System.out.println("step8");
		return testA;
	}
	
	public String test(){
		System.out.println("step1");
		return super.test();
	}

	public static void main(String[] args) {
		System.out.println(new TestC().test());
	}

	@Override
	public TestB getTestB() {
		System.out.println("step3");
		TestC testC = new TestC();
		System.out.println("step5");
		return testC;
	}

}



运行TestC.java的main方法,得到结果如下:


step4:constructorC
step1
step2
step3
step4:constructorC
step5
step6
step7:constructorA
step8
step9
step10
36c750665f084696846a24a88c63e312

你可能感兴趣的:(java,spring)