23种模式中的代理模式:
package com.proxy.pattern;
/***
* A忙没空 找B代理帮忙
* 代理人知道被代理人要做的事情
* 两人有共同的接口
* @author weizhi3
*
*/
public interface KindMan {
/***
* 取货
*/
public void pickUp();
/***
* 付钱
*/
public void payMoney();
}
package com.proxy.pattern;
/***
* 代理人
* @author weizhi3
*
*/
public class OtherB implements KindMan{
private KindMan kindMan = null;
public OtherB(){
}
public OtherB(KindMan kindMan){
this.kindMan = kindMan;
}
public void payMoney() {
this.kindMan.payMoney();
}
public void pickUp() {
this.kindMan.pickUp();
}
}
package com.proxy.pattern;
/***
* 快递哥来送货了
* @author weizhi3
*
*/
public class ExpressBrother {
public static void main(String[]args){
OtherB other = new OtherB(new Mea());
other.pickUp();
other.payMoney();
}
}