Using the Decorator Pattern

Using the Decorator Pattern: “The main difference between subclassing and the Decorator pattern is this: with subclassing, you work with the class, whereas in the Decorator pattern, you modify objects dynamically. When you extend a class, the change you make to the child class will affect all instances of the child class. With the Decorator pattern, however, you apply changes to each individual object you want to change.” [onjava]

One of the comments at the end of the article mentions that the Decorator pattern is always illustrated using UI components (and, in fact, the first couple pages of Design Patterns uses only UI type examples, Design Patterns also mentions using the Decorator pattern with streams). What other uses can the Decorator pattern be put to? Better, in what ways have you used the Decorator pattern?

One thought on “Using the Decorator Pattern”

Leave a Reply

Your email address will not be published. Required fields are marked *