Why decorator is a structural and not behavioral design pattern?
Asked Answered
V

2

12

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.

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. Why decorator is a structural pattern?
  2. What is the criteria of a structural pattern?
  3. What is the criteria of a behavioral pattern?

Thanks.

Vashti answered 9/4, 2013 at 15:48 Comment(3)
oh yeah, I'm glad java doesn't mess with that stuff, I was reading a Python book, and It was talking about the Decorator, and oh boy was my head burning.Snodgrass
@anakata: A Decorator in Python is a language construct; this question refers to the Decorator design patternLumberjack
I better start reading about this kind off stuff XDSnodgrass
S
14

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.

Scarron answered 9/4, 2013 at 16:21 Comment(0)
P
3

If you need an answer in terms of your quote: The change in behavior is due to structural modification.
I.e. you "decorate" an object (via specific structuring of your class) to achieve the required behavior (via delegation)

Pasteurism answered 9/4, 2013 at 15:52 Comment(1)
I did not get it. I think, every pattern imposes some structure, right?Vashti

© 2022 - 2024 — McMap. All rights reserved.