静态代理的代理模式

//通过代理接口
interface ClothFactory{
	public void productCloth();
}

//被代理类
class NikeClothFactory implements ClothFactory{

	@Override
	public void productCloth() {
		System.out.println("Nike 生产衣服");
	}
}
//代理接口
interface ProxyFactory{
	public void product();
}

//代理类
class NikeProxyFactory implements ProxyFactory{

	ClothFactory clothFactory;
	
	public NikeProxyFactory(ClothFactory clothFactory){
		this.clothFactory = clothFactory;
	}
	
	@Override
	public void product() {
		System.out.println("代理类运行,收代理费");
		clothFactory.productCloth();
	}
	
}


public class TestStaticProxy {

	/**
	 * @Title: main
	 * @Description:
	 * @param:
	 * @return void 
	 * @user: wangzg
	 * @Date:2014-10-27
	 * @throws
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		ClothFactory clothFactory = new NikeClothFactory();
		
		ProxyFactory proxyFactory = new NikeProxyFactory(clothFactory);
		
		proxyFactory.product();
	}

}

版权声明:本文博客原创文章,博客,未经同意,不得转载。

posted on 2015-08-12 11:09  gcczhongduan  阅读(131)  评论(0编辑  收藏  举报