In our ongoing series about design patterns, we introduce the Decorator Pattern. The decorator pattern serves to add specific functionality to an existing class. The classic example of this is in GUI programming, when a widget needs a border, or graphic surrounding it. Not using the Decorator Pattern, one might just subclass out the widget class and add a border to the subclassed widget. This becomes more difficult however, when there are multiple classes of widgets. This becomes almost impossible when dealing with a collection of widgets.
So, enter the Decorator Pattern. (more…)