Summary
That’s going to close out our Decorator pattern discussion, but let’s review the key points before you jump to your own projects. First, the Decorator pattern is best used when you want to change the skin of an object instance and not the inner workings of its class. If you want to dynamically change the guts of a class, refer to Chapter 12, Swapping Algorithms with the Strategy Pattern. This solution is a wonderful option in lieu of inheritance and large class hierarchies.
The Decorator pattern is made up of the main Component interface, concrete Component classes, the Decorator abstract class, and concrete Decorator classes. Both the concrete Components and concrete Decorators in your projects need to implement the Component interface so the client can treat them the same. Your decorators function as transparent wrappers for the Components you want to decorate, adding or modifying the Component in some way while also calling the Components’ base...