码迷,mamicode.com
首页 > 其他好文 > 详细

代理模式之静态代理

时间:2014-10-27 15:43:54      阅读:189      评论:0      收藏:0      [点我收藏+]

标签:java   设计模式   代理模式   静态代理   

//被代理接口
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();
	}

}

代理模式之静态代理

标签:java   设计模式   代理模式   静态代理   

原文地址:http://blog.csdn.net/sd_tz_wzg/article/details/40507135

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!