Question

Can anybody explain why the name "Decorator" was chosen for the functionality conveyed by the Decorator design pattern?

I've always found that name fairly misleading, because decorator and marking interface sound very similar to me in their purpose. However, whereas a marker does not really "do anything", decorators certainly do. But the term decorations to me implies passivity, which isn't really the case with this pattern that is used to add functionality.

Was it helpful?

Solution

I believe that the origin of the term comes from the example use of decorating a user interface with different components, for example, scrollbars, close buttons, etc.

EDIT: Reference Page 308 in "Design Patterns in C#" by Steven John Metsker:

One of the original applications of DECORATOR (and presumably the application from which DECORATOR derives its name) lies in the construction of GUI components.

OTHER TIPS

I think the analogy is that when you decorate a house you don't really break any walls or anything like that, you just put some stuff around (as many as you want) in a way that changes how it looks (and its functionality). I think this word was chosen to imply non-intrusiveness, and also something optional.

A decorator "decorates" an interface by adding extra functionality to existing methods, but not actually adding any of its own. The decoration is not essential to the base functionality; otherwise it would have been built into the base class.

Because you are adding new functionality to an existing object. In essence, you are "decorating" the object with the new functionality.

Hey, leave it to geeks to make up names.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top