代理模式之靜態代理

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

}

發佈了146 篇原創文章 · 獲贊 260 · 訪問量 23萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章