结构型-适配器

使用不完全匹配的功能(目的是合并)。

案例 AOP BeforeAdvice

aop

黄色是适配器,把橙色装入紫色,变成蓝色的子类,供绿色使用。
就完成了橙色到蓝色的适配。

黄色代码:

	public MethodInterceptor getInterceptor(Advisor advisor) {
		MethodBeforeAdvice advice = (MethodBeforeAdvice) advisor.getAdvice();
		return new MethodBeforeAdviceInterceptor(advice);
	}

当其他对象调用通过绿色返回的蓝色的时候,实际上调用的是紫色中的橙色。
紫色代码:

	public Object invoke(MethodInvocation mi) throws Throwable {
		this.advice.before(mi.getMethod(), mi.getArguments(), mi.getThis());
		return mi.proceed();
	}

AOP由此完成了before的功能

posted @ 2020-11-07 15:38  qianbuhan  阅读(42)  评论(0)    收藏  举报