代理模式:一个对象帮另一个对象做事情,例如,一个Person 请 Lawyer 打官司(case),自己不懂法律知识,请Lawyer做代理

代码示例
/**
* @author apple
*
* 官司接口,处理案件
*/
public interface ICase {
// 处理案件
public void casehandle();
}
/**
*
* @author apple
*
* 代理律师
*
*/
public class Lawyer implements ICase {
private ICase icase;
public Lawyer(ICase icase) {
super();
this.icase = icase;
}
private void checkoutMaterials() {
System.out.println("审核官司材料");
}
@Override
public void casehandle() {
// TODO Auto-generated method stub
checkoutMaterials();
this.icase.casehandle();
}
}
/**
*
* @author apple
*
* 上诉人
*
*/
public class Person implements ICase {
@Override
public void casehandle() {
// TODO Auto-generated method stub
System.out.println("我要打官司");
}
}
/**
*
* @author apple
*
* 测试类
*
*/
public class Test {
public static void main(String[] args) {
// TODO Auto-generated method stub
ICase icase = null;
icase = new Lawyer(new Person());
icase.casehandle();
}
}
/*
审核官司材料
我要打官司
*/
网友评论