---
title: "【读书笔记】HeadFirst设计模式——代理和装饰者"
author: "nathan09"
date: "2012-03-25T01:36:00Z"
tags: []
slug: "headfirst"
draft: false
lastmod: "2012-12-06T11:27:35Z"
id: 1742528
url: "https://nathan09.iteye.com/blog/1742528"
---

代理——控制对主题的访问，有时控制主题的创建，完全代替主题，或者什么都不做，只是简单转发

装饰者——只添加新功能，不做其他控制

从使用者的角度看，代理一般不改变对象行为，装饰肯定会增加对象行为。

代理：

![](http://hi.csdn.net/attachment/201203/24/0_13326107698akF.gif)

装饰者：

![](http://hi.csdn.net/attachment/201203/24/0_1332610792wLHA.gif)