Why is a decorator a structural rather than a behavioral design pattern?

I consider myself an intermediate knowledge of GoF design patterns. However, I am embarrassed when it comes to classifying these patterns into structural and behavioral models. I have no confusion about the creation patterns.

From wikipedia - Decorator Pattern - in object-oriented programming, the decorator pattern is a design pattern that allows you to add behavior to a single object, statically or dynamically, without affecting the behavior of other objects from the same class.

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

  • Why is the decorator a structural template?
  • What are the criteria for a block diagram?
  • What are the criteria for behavior?

Thanks.

+4
source share
2 answers

Behavioral patterns relate to communication between separate objects: things, such as an intermediary, an observer, a chain of responsibility (even a visitor, which is described as โ€œseparating the algorithm from the structure of the object on which it worksโ€). They indicate how individual objects interact.

Structural patterns relate to layering and abstraction of layers; these are things like an adapter, bridge, and composite. Decorator is a way of creating functionality, so it comes with structural templates.

+5
source

If you need an answer in terms of your quote: a change in behavior is associated with a modification of the structure .
That is, you "decorate" the object (through the specific structuring of your class) to achieve the desired behavior (through delegation)

0
source

All Articles