首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件开发 >

设计方式读书笔记-1代理模式Proxy(2)

2012-06-26 
设计模式读书笔记-1代理模式Proxy(2)1.虚拟代理与状态模式相结合Statepackage headfirst.proxy.virtualpro

设计模式读书笔记-1代理模式Proxy(2)
1.虚拟代理与状态模式相结合
State

package headfirst.proxy.virtualproxy;import java.awt.Component;import java.awt.Graphics;import java.net.URL;import javax.swing.Icon;class ImageProxyWithState implements Icon {    State currentState; State imageNotLoadedState;State imageLoadedState;    public ImageProxyWithState(URL url) { imageNotLoadedState = new ImageNotLoadedState(this, url);imageLoadedState = new ImageLoadedState();currentState = imageNotLoadedState;}     public State getCurrentState() {return currentState;}public void setCurrentState(State currentState) {this.currentState = currentState;}public State getImageNotLoadedState() {return imageNotLoadedState;}public void setImageNotLoadedState(State imageNotLoadedState) {this.imageNotLoadedState = imageNotLoadedState;}public State getImageLoadedState() {return imageLoadedState;}public void setImageLoadedState(State imageLoadedState) {this.imageLoadedState = imageLoadedState;}public int getIconWidth() {return currentState.getIconWidth();} public int getIconHeight() {return currentState.getIconHeight();}     public void paintIcon(final Component c, Graphics  g, int x,  int y) {currentState.paintIcon(c, g, x, y);}}


2.Java动态代理实现机制及扩展
http://www.ibm.com/developerworks/cn/java/j-lo-proxy1/
http://www.ibm.com/developerworks/cn/java/j-lo-proxy2/

热点排行