2021-02-08 23:37:48 +08:00
|
|
|
---
|
|
|
|
layout: pattern
|
|
|
|
title: Delegation
|
|
|
|
folder: delegation
|
2021-08-01 22:55:54 +08:00
|
|
|
permalink: /patterns/delegation/
|
2021-02-08 23:37:48 +08:00
|
|
|
categories: Structural
|
2021-05-19 10:49:05 -06:00
|
|
|
language: zh
|
2021-02-08 23:37:48 +08:00
|
|
|
tags:
|
|
|
|
- Decoupling
|
|
|
|
---
|
|
|
|
|
|
|
|
## 或称
|
|
|
|
代理模式
|
|
|
|
|
|
|
|
## 目的
|
|
|
|
它是一种让对象将某种行为向外部表达,但实际上将实现该行为的责任委托给关联对象的技术。
|
|
|
|
|
|
|
|
## 类图
|
2021-08-01 22:55:54 +08:00
|
|
|

|
2021-02-08 23:37:48 +08:00
|
|
|
|
|
|
|
## 适用性
|
|
|
|
使用委托模式以实现以下目的
|
|
|
|
|
|
|
|
* 降低类的耦合性
|
|
|
|
* 组件的行为相同,但是意识到这种情况将来可能会改变。
|
|
|
|
|
|
|
|
## 鸣谢
|
|
|
|
|
|
|
|
* [Delegate Pattern: Wikipedia ](https://en.wikipedia.org/wiki/Delegation_pattern)
|
|
|
|
* [Proxy Pattern: Wikipedia ](https://en.wikipedia.org/wiki/Proxy_pattern)
|