The decorator design pattern allows you to replace an object with a wrapper around that object. Many of the messages to the wrapper are passed directly to the target object and others are either intercepted or modified on the way. This design pattern allows you to change the behavior of an object and to abstract that change into another object. You can effectively wrap an object inside another to change its functionality.
Decorators work well for what they do, but if you push them very far outside their intended use, they start to become cumbersome. Sometimes decorators add additional functionality and respond to new methods that the target object didn't. This means that the client code needs to know it's talking to a decorator. Sometimes decorators are chained to create a sequence of decorators. These chains sometimes become order-dependent and difficult to construct correctly. Finally, when you need to access behavior from an object in the middle of the decorator chain, it can be difficult getting to the right decorator.
I've seen many designs that started out using decorators that later switched to simpler techniques.
Download