装饰模式(Decorator)

简介: Decorator Pattern:   Attach additional responsibilities to an object dynamically.   Decorators provide a flexible alternative to subclassing for extending functionality.

Decorator Pattern:

  Attach additional responsibilities to an object dynamically.

  Decorators provide a flexible alternative to subclassing for extending functionality.

 

什么是装饰模式?

  装饰模式被用来应对类型在继承过程中快速膨胀的情况,而导致膨胀的原因往往是我们需要为类型增加新的职责(功能)

 

现实生活中的例子:

   手机从一开始的只能打电话,收发短信,到后来的听MP3, GPS, 拍照,智能化功能等等

 

装饰模式的目的:

   动态为对象增加新的职责

 

 

目录
相关文章
|
6月前
|
设计模式
设计模式13 - 装饰模式【Decorator Pattern】
设计模式13 - 装饰模式【Decorator Pattern】
15 0
|
11月前
|
设计模式 Java
Java设计模式-装饰器模式(Decorator)
Java设计模式-装饰器模式(Decorator)
结构型模式 - 装饰器模式(Decorator Pattern)
结构型模式 - 装饰器模式(Decorator Pattern)
|
设计模式
装饰模式(Decorator)
装饰模式(Decorator)
|
设计模式 缓存 Java
设计模式-Adapter适配器模式和Decorator装饰者模式
设计模式-Adapter适配器模式和Decorator装饰者模式
设计模式-Adapter适配器模式和Decorator装饰者模式
|
设计模式 自动驾驶
装饰器模式Decorator
煎饼果子装饰器&汽车装饰器
526 3
装饰器模式Decorator
|
设计模式 缓存 Java
结构型-Decorator
装饰器模式主要解决继承关系过于复杂的问题,通过组合来替代继承。它主要的作用是给原始类添加增强功能。这也是判断是否该用装饰器模式的一个重要的依据。除此之外,装饰器模式还有一个特点,那就是可以对原始类嵌套使用多个装饰器。为了满足这个应用场景,在设计的时候,装饰器类需要跟原始类继承相同的抽象类或者接口。
82 0
|
设计模式 uml
设计模式——装饰模式(Decorator)
设计模式——装饰模式(Decorator)
138 0
设计模式——装饰模式(Decorator)
|
设计模式 Java
Java设计模式——装饰模式(Decorator Pattern)
Java设计模式——装饰模式(Decorator Pattern)
171 0
Java设计模式——装饰模式(Decorator Pattern)
|
设计模式 Java
浅谈JAVA设计模式之——装饰模式(Decorator)
动态地给一个对象添加一些额外的职责。就增加功能来说,Decorator模式相比生成子类更为灵活。
139 0
浅谈JAVA设计模式之——装饰模式(Decorator)