代理模式
应用软件所提供的桌面快捷方式是快速启动应用程序的代理,桌面快捷方式一般使用一张小图片来表示(Picture),通过调用快捷方式的run()方法将调用应用软件(Application)的run()方法。使用代理模式模拟该过程,绘制类图并编程实现。
package ProxyPattern;
interface Software
{
void run();
}
class Application implements Software
{
public void run() {
System.out.println("Application is running!");
}
}
public class ProxyPattern implements SoftWare {
private Application application = new Application();
public void run() {
application.run();
}
public class FastwayProxyClient
{
public static void main(String[] args) {
ProxyPattern proxy = new ProxyPattern();
proxy.run();
}
}
运行结果: