java代理模式

2014-11-24 03:29:11 · 作者: · 浏览: 0
package com.liao.proxy;
/**
* 代理模式
* @author liaoyp
*
*/
public class ProxyTest {// 代理目标

public static void main(String[] args) {

Proxy proxy = new Proxy();
proxy.handQuesttion();
}
}


// 虚拟目标
interface AbstractTaget{

public void handQuesttion();
}
/**
*
* @author liaoyp
* 商家
*
*/
class RealTaget implements AbstractTaget{

@Override
public void handQuesttion() {
// 真实目标处理对象
System.out.println("商家开始处理");
}
}
/**
*
* @author liaoyp
* 代理商
*/
class Proxy implements AbstractTaget{

RealTaget taget = new RealTaget();

@Override
public void handQuesttion() {
// TODO Auto-generated method stub

preHander();

taget.handQuesttion();

postHander();

}
// 处理之前
public void preHander(){

System.out.println("通知商家开始处理!");

}
// 处理之后
public void postHander(){

System.out.println("商家处理完毕!");
}

}

摘自 android小益的专栏