When is it necessary to use the decorator pattern? If possible, give me a real world example that is well-suited for the pattern.
You asked for a real-world example, so here you go: download (or browse) DonsProxy from github:
git://github.com/DonBranson/DonsProxy.git
DonsProxy basically uses a WireTap pattern to let you watch or extract HTTP traffic, plus it lets you modify the connection behavior to simulate suboptimal connections. I use the Decorator pattern to modify channels based on user options. Command-line or GUI options (dependinvg on which View they're using) allows latency injection and bandwidth injection, among other things. When they inject latency, that adds the LatencyDecorator to the channel; if they throttle the bandwidth, that adds the ThrottleDecorator to the channel. Since this use a decorator pattern, they can mix-and-match behavior to their heart's content.