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

署理模式的UML类图与实现源码

2012-10-24 
代理模式的UML类图与实现源码以下是一个代理模式的UML图:源码:Image接口?public interface Image { void s

代理模式的UML类图与实现源码

以下是一个代理模式的UML图:


署理模式的UML类图与实现源码

源码:Image接口

?

public interface Image { void show();}

?BigImage类

?

public class BigImage implements Image {public BigImage(){try {//系统延时3秒用来模拟调用大图片时有系统延时Thread.sleep(3000);System.out.println("Image Successfully loaded.");} catch (InterruptedException e) {// TODO: handle exceptione.printStackTrace();}}public void show() {System.out.println("Draw Real Image");}}
?

?ImageProxy类

?

public class ImageProxy implements Image {private Image image;public ImageProxy(Image image){this.image=image;}public void show() {if(image==null){image=new BigImage();}image.show();}}
?

?

?

BigImageTest类(客户端)

?

public class BigImageTest {public static void main(String[] args) {System.out.println("使用代理");               //null,确保每次调用show方法需要示例化BigImageImage image=new ImageProxy(null);System.out.println("开始显示图片");image.show();System.out.println("***************************************");System.out.println("没使用代理");Image image2=new BigImage();image2.show();}}
?

?

热点排行