mirror of
https://github.com/CyC2018/Interview-Notebook.git
synced 2026-11-19 13:33:45 +00:00
Update 设计模式 - 代理.md
文字校对,示例代码补上 import。
This commit is contained in:
+6
-1
@@ -8,7 +8,7 @@
|
||||
|
||||
- 远程代理(Remote Proxy):控制对远程对象(不同地址空间)的访问,它负责将请求及其参数进行编码,并向不同地址空间中的对象发送已经编码的请求;
|
||||
- 虚拟代理(Virtual Proxy):根据需要创建开销很大的对象,它可以缓存实体的附加信息,以便延迟对它的访问,例如在网站加载一个很大图片时,不能马上完成,可以用虚拟代理缓存图片的大小信息,然后生成一张临时图片代替原始图片;
|
||||
- 保护代理(Protection Proxy):按权限控制对象的访问,它负责检查调用者是否具有实现一个请求所必须的访问权限;
|
||||
- 保护代理(Protection Proxy):按权限控制对象的访问,它负责检查调用者是否具有实现一个请求所必需的访问权限;
|
||||
- 智能代理(Smart Reference):取代了简单的指针,它在访问对象时执行一些附加操作,例如记录对象的引用次数、第一次引用对象时将它装入内存、访问实际对象前检查是否已经锁定了它。
|
||||
|
||||
<div align="center"> <img src="pics/dp-proxy.png" width="760px"/> </div><br>
|
||||
@@ -23,6 +23,8 @@ public interface Image {
|
||||
```
|
||||
|
||||
```java
|
||||
import java.net.URL;
|
||||
|
||||
public class HighResolutionImage implements Image {
|
||||
|
||||
private URL imageURL;
|
||||
@@ -83,6 +85,9 @@ public class ImageProxy implements Image {
|
||||
```
|
||||
|
||||
```java
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
|
||||
public class ImageViewer {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user