用途
代理模式 (Proxy)
为其他对象提供一种代理以控制对这个对象的访问。
代理模式是一种结构型模式。
结构
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAjYAAADxCAIAAABXpmpHAAAgAElEQVR4nO3dd0AT5//A8QhC9WdduOv6fkXrwNVhUSlaq5V+27pwoJRWccvQ2rpFAoRRW8WKIojGDThARWxFURCoiIutIKIM2Us2Cbm75/fHQ44jEAghCSf5vP7Sh8vdQQLv5PLkjoMAAAAAVuK09w4AAAAATYNEAQAAYClIFAAAAJaCRAEAAGApSBQAAACWgkQBAABgKUgUAAAAloJEAQAAYClIFAAAAJaCRAEAAGApSBQAAACWgkQBAABgKUgUAAAAloJEAQAAYClIFAAAAJaCRAEAAGApSBRgGYpEZDVCVHvvBwCg/UGiANuQiKyBRDWLQqQQIbK9dwMApYNEAfDeoRBRhShIFOj4IFGA1SorKzOBFJWVle19/wCgXJAowGrnzp3rDqQ4ffp0e98/ACgXJAqwGp/P19PTiwK0hw+iHoRERT2cOHGil5eX+OdEIaISUUR73lUAKAEkCrAan8/X19dv771gFRJRtQghAwODBomiamGOCeh4IFGA1SBR0jRMFAAdEyQKsBokShpIFFAHkCjAaopLFNWa42DKm8+tsDVDooA6gEQBVlNYokghImScok0hohxRIgVstPGaReWKmtQAiQLqABIFWE2Rr6Jk/6wrReCXXP7+/lOmTJkzZ05RUZEi9qF+zW0HiQLqABIFWE2x70VVVVVt2bJlJYOFhcW7d++kLe/h4cHhcPr06ZObm9v4qy4uLitXrjx79mzrdoIUnDl9cuXKlb///ntr958JEgXUASQKsJqiEhUbG7t//34XF5ddu3btYOByueXl5U3eJDg42NjYeOjQodKW8fT03LFjx9WrV1u1Jz7eZ6ZNnfLpp58eP368wRcoAs8mlxEkCqgDSBRgNUUlysvLi8Ph9OrVKzs7mzleW1t7586dwMDAN2/eIISKi4sDAwMDAwMLCwutra05HM748eMDxdLS0pjL0CNFRUWBDAkJCfT6IyMj6fE7d+4IhcIZM2ZwOJx58+bRI3WL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qGwRHU4kCjAfvWJauFS11JBopQFEqUQkChpIFGA/RgH+uSceQuJUhZIlEJAoqSBRAH2g/ei2AsSpRCQKGkgUYD9IFHsBYlSCEiUNO97ogYMGHDy5MkzoEPbu3cvJIqlIFEKAYmS5r1OVFhY2BSgHmbPnt2W88dDopQFEqUQkChp3utEASAjSJSyQKIUAhIlDSQKvGfIGjnOKwiJUhZIlEJAoqSBRIH3jFxnPoREKQskSiEgUdJAooA6gEQpCyRKISBR0kCigDpQTKKOHz8eBRrauHEjJKrt+Hy+np5ee9+ZbDRx4kRIFOjw2pqo3NzcYcOGdQdN+fHHHxVyJ6mzc+fOtffdyF6nT59u7/sHAOVqa6IIgsjKysoETWnLpwEAVllZ2d53I3tVVrLiEvUAKI+8iSKFbblaMABAYShCOZdeBaD9yZuoNlyHEQCgUCQ8XwQdVVsP9IHmUKScV/4FGEXAMyEA1BkkSpkoESKq2nsn3mekEJFwMmwA1BckCgAAAEtBogAAALAUJAoAAABLQaIAAACwFCQKAAAAS0GiAAAAsBQkCgAAAEtBogAAALAUJAoAAABLQaIAAACwFCQKAAAAS0GiAAAAsBQkCgAAAEtBogAAALAUJAoAAABL/T9fNSRtSbnNxwAAAABJRU5ErkJggg==" alt="" />
图-代理模式结构图
Subject : 定义了 RealSubject 和 Proxy 的公共接口,这样就在任何使用 RealSubject 的地方都可以使用 Proxy 。
abstract class Subject { public abstract void Request(); }
RealSubject : 定义 Proxy 所代表的真实实体。
class RealSubject extends Subject { @Override public void Request() { System.out.println("真实的请求"); } }
Proxy : 保存一个引用使得代理可以访问实体,并提供一个与 Subject 的接口相同的接口,这样代理就可以用来替代实体。
class Proxy extends Subject { private RealSubject real; @Override public void Request() { if (null == real) { real = new RealSubject(); } real.Request(); } }
应用场景
1、远程代理
为一个远程对象在不同地址空间提供本地化代表。
2、虚拟代理
根据需要创建开销很大的对象。通过它来存放实例化需要很长时间的真实对象。
3、安全代理
用来控制真实对象的访问权限。
4、智能指引
是指当调用真实对象时,代理处理另外一些事。
要点
代理模式介绍了一种访问对象的间接等级。
一个远程代理可以隐藏一个对象在不同地址空间的细节。
一个虚拟代理可以根据需要最优化创建对象的开销。
而安全代理和智能指引都允许访问对象的同时处理其他事务。