为什么装饰器是结构性的而不是行为设计​​模式? [英] Why decorator is a structural and not behavioral design pattern?

查看:86
本文介绍了为什么装饰器是结构性的而不是行为设计​​模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为自己具有GoF设计模式的中级知识。但是,在将这些模式分为结构和行为模式时,我感到困惑。我对创建模式没有任何困惑。

I consider myself having intermediate knowledge of GoF design patterns. However, I get confused when it comes to classifying those patterns into structural and behavioral patterns. I do not have any confusion about creational patterns.

来自Wikipedia-装饰器模式-在面向对象的编程中,装饰器模式是允许行为,可以静态或动态地添加到单个对象中,而不会影响同一类中其他对象的行为。

From wikipedia - Decorator Pattern - In object-oriented programming, the decorator pattern is a design pattern that allows behavior to be added to an individual object, either statically or dynamically, without affecting the behavior of other objects from the same class.

从上面的定义中,很明显,它与行为有关,然后

From the above definition it is clear that it is about behavior, then


  1. 为什么装饰器是结构模式?

  2. 结构模式的标准是什么?

  3. 行为模式的标准是什么?

谢谢。

推荐答案

行为模式是关于单独对象之间的通信的:中介者,观察者,链之类的东西责任(甚至访问者,也被描述为将算法与操作对象的结构分离)。它们指定了分离的对象如何交互。

Behavioral patterns are about communication between separate objects: things like mediator, observer, chain of responsibility (even visitor, which is described as "separating an algorithm from the object structure on which it operates"). They specify how separate objects interact.

结构模式是关于组成和分层抽象的方法,它们是适配器,桥接和复合之类的东西。装饰器是一种用于组合功能的技术,因此它与结构模式一起使用。

Structural patterns are about ways to compose and layer abstractions, they are things like adapter, bridge, and composite. Decorator is a technique for composing functionality, so it goes with the structural patterns.

这篇关于为什么装饰器是结构性的而不是行为设计​​模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆