Decorating without Decorator

Having seen some good examples of DECORATOR, it is important to note that similar designs allow for “decorating” an object without applying the DECORATOR pattern. Two areas that can be mistaken for DECORATOR are the use of Swing borders and listeners.

A GUI framework developer might apply DECORATOR in establishing how GUI components get borders. To do so, you can create a hierarchy of components that expect another component in their constructor and distribute a paint() method across this hierarchy. Border classes in this hierarchy would paint their border and then forward the paint() call to the component they wrap. Swing, however, does not work this way.

Swing anticipates that any component might need a border, ...

Get Design Patterns Java™ Workbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.