标签:des style blog http java color
不想让客户端直接访问具体实现接口,客户端不应该直接访问具体实现,一般会涉及到以下四个对象
package com.lipan.designpattern;
/*
* @author:lipan
*
* */
public interface BizInterface {
public void doSomeBizWork();
}
package com.lipan.designpattern;
public class BizProxy implements BizInterface{
private BizRealService obj;
@Override
public void doSomeBizWork() {
if(obj == null){
obj = new BizRealService();
}
System.out.println("do some non-biz work before real biz work");
obj.doSomeBizWork();
System.out.println("do some non-biz work after real biz work");
}
}
package com.lipan.designpattern;
public class BizRealService implements BizInterface{
@Override
public void doSomeBizWork() {
// TODO Auto-generated method stub
System.out.println("Do some real work in Class BizRealService!");
}
}
package com.lipan.test;
import com.lipan.designpattern.*;
public class TestProxy {
public static void main(String[] args) {
// TODO Auto-generated method stub
BizProxy bp = new BizProxy();
bp.doSomeBizWork();
}
}
设计模式学习之代理模式(Proxy),布布扣,bubuko.com
标签:des style blog http java color
原文地址:http://www.cnblogs.com/obama/p/3831569.html