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, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access