views:

786

answers:

4

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.

A: 

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.

+2  A: 

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.

Edward Z. Yang
But doesn't "decorate" mean that you add something insubstantial?
Uri
It's only a metaphor. It works because we've agreed what it means in a software design sense. The fact that it's not a perfect metaphor doesn't detract from its utility as long as it's good enough.
tvanfosson
+7  A: 

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.

tvanfosson
+3  A: 

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.

rodbv