3、ements Phone { 4. 5. private String owner; 6. 7. public IPhone4S(String owner) { 8. this.owner = owner; 9. } 10. 11. @Override 12. public void show() { 13. System.out.println("I'm " + owner 14. + "'s IPhone4S which can do nothing whi
4、le just a phone!"); 15. } 16.} [java] viewplaincopy1.package com.designpattern.proxy; 2. 3.public class Proxy implements Phone { 4. 5. private String owner; 6. private IPhone4S phone; 7. 8. public Proxy(String owner) { 9. this.owner = owner; 10. } 11.
5、1. @Override 2. public void show() { 3. if (phone == null) { 4. phone = new IPhone4S(owner); 5. } 6. phone.show(); 7. 8. } 9.} [java] viewplaincopy1.package com.designpattern.proxy; 2. 3.public class Client { 4. public static void m
6、ain(String[] args) { 5. Proxy proxy = new Proxy("halberd"); 6. proxy.show(); 7. } 8.} [html] viewplaincopy1.I'm halberd's IPhone4S which can do nothing while just a phone! 这样就简单的实现了代理模式,其实对于大多数结构型模式来说都一样,解决问题的思想是一样的,都是从添加中间件的方式达到一个解耦合的作用。使用代理模式,能够在不改变原来代码工商的基础上对某一对