I understand completely how to implement the Decorator pattern, and I also understand what it's intent is.
The Decorator is used in one of two cases:
As an alternative to subclassing - when there are multiple characteristics that an object can have, one could use inheritance in order to create subclasses for all the possible combinations. For example, three characteristics A, B and C will results in lots of classes: A, B, C, ABC, AB, AC, BC. This results in a 'class explosion'. With Decorator, one would have three decorators A, B and C, and a class D to 'decorate' - and that's it.
As a way to expand an object's functionality during runtime - we can decide which decorators to 'wrap' an object with during runtime, thus 'customizing' an object dynamically.
This was just to show that I do understand what Decorator is (I also totally understand how it's implemented). Now my question:
I'm familiar with theoretical examples of when and how to use Decorator. And as you can see I know what is it's intent. But I'm still not sure when to actually use this in practice, in an actual application. Telling me "it's used as an alternative to subclassing", or "it's used to dynamically add functionality to an object" won't be helpful since I'm familiar with it's intent.
Also telling me "think of a UI window for example. It can have a border, or not, and can be resizable, or not" isn't helpful, I'm already familiar with these theoretical examples.
So what I'm asking for is a concrete real world example of Decorator, in a practical, real-world scenario, with a brief explanation of the benefits of using a Decorator pattern there over other techniques.
Just to clarify, I'm not looking for a list of applications where Decorator was utilized. I'm looking for an example of where and how Decorator was used in a design, why it was a good design choice and the concrete problem that it solved. When I'll see concrete problem solved with Decorator hopefully I'll understand it better.
InputStream
,Reader
, andInputStreamReader
and thinking how you might implement the latter without using the Decorator pattern.